Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add note about wrong error code in type: ignore #12067

Merged
merged 3 commits into from
Jan 25, 2022
Merged

Conversation

JukkaL
Copy link
Collaborator

@JukkaL JukkaL commented Jan 25, 2022

If we change the error code of a message, it can result in existing
"type: ignore" comments being ignored. If this seems to be the case,
add a note that hints about changing the ignored error code.

Give a more specific message for a set of special cased error codes
where we know the original error code. In other cases give a more
vague message.

If we change the error code of a message, it can result in existing
"type: ignore" comments being ignored. If this seems to be the case,
add a note to suggest changing the ignored error code.
@JelleZijlstra
Copy link
Member

Would it make sense to just always print this note if we detect a # type: ignore for the wrong code? It will be difficult to keep the hardcoded dictionary up to date, and it will always be helpful to alert users that they may be using the wrong error code.

@github-actions

This comment has been minimized.

@JukkaL
Copy link
Collaborator Author

JukkaL commented Jan 25, 2022

That's a good idea. I'll add a fallback where we give a less specific error message if the error code is not in the dictionary. I think that it's still useful to maintain the dictionary, even if it's on a best-effort basis.

@JukkaL JukkaL changed the title Add note about changed error codes, such as literal-required Add note about wrong error code in type: ignore Jan 25, 2022
@github-actions
Copy link
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

pydantic (https://github.com/samuelcolvin/pydantic)
+ pydantic/networks.py:268: note: Error code changed to literal-required; "type: ignore" comment may be out of date
+ pydantic/networks.py:313: note: Error code changed to literal-required; "type: ignore" comment may be out of date
+ pydantic/networks.py:314: note: Error code changed to literal-required; "type: ignore" comment may be out of date

ignite (https://github.com/pytorch/ignite)
+ ignite/contrib/handlers/tensorboard_logger.py:155: note: Error code "import" not covered by "type: ignore" comment

aioredis (https://github.com/aio-libs/aioredis)
+ aioredis/connection.py:1201: note: Error code changed to literal-required; "type: ignore" comment may be out of date
+ aioredis/connection.py:1205: note: Error code changed to literal-required; "type: ignore" comment may be out of date

spark (https://github.com/apache/spark)
+ python/pyspark/sql/pandas/types.py:238: note: Error code "import" not covered by "type: ignore" comment
+ python/pyspark/sql/pandas/conversion.py:565: note: Error code "import" not covered by "type: ignore" comment
+ python/pyspark/sql/pandas/functions.pyi:70: note: Error code "name-defined" not covered by "type: ignore" comment
+ python/pyspark/pandas/typedef/typehints.py:32: note: Error code "import" not covered by "type: ignore" comment
+ python/pyspark/pandas/utils.py:43: note: Error code "import" not covered by "type: ignore" comment
+ python/pyspark/pandas/indexing.py:27: note: Error code "import" not covered by "type: ignore" comment
+ python/pyspark/pandas/generic.py:41: note: Error code "import" not covered by "type: ignore" comment
+ python/pyspark/pandas/frame.py:54: note: Error code "import" not covered by "type: ignore" comment
+ python/pyspark/pandas/base.py:28: note: Error code "import" not covered by "type: ignore" comment
+ python/pyspark/pandas/data_type_ops/categorical_ops.py:23: note: Error code "import" not covered by "type: ignore" comment
+ python/pyspark/pandas/categorical.py:21: note: Error code "import" not covered by "type: ignore" comment
+ python/pyspark/pandas/series.py:50: note: Error code "import" not covered by "type: ignore" comment
+ python/pyspark/pandas/groupby.py:47: note: Error code "import" not covered by "type: ignore" comment
+ python/pyspark/pandas/groupby.py:50: note: Error code "import" not covered by "type: ignore" comment
+ python/pyspark/pandas/indexes/base.py:35: note: Error code "import" not covered by "type: ignore" comment
+ python/pyspark/pandas/indexes/timedelta.py:21: note: Error code "import" not covered by "type: ignore" comment
+ python/pyspark/pandas/indexes/numeric.py:20: note: Error code "import" not covered by "type: ignore" comment
+ python/pyspark/pandas/indexes/multi.py:22: note: Error code "import" not covered by "type: ignore" comment
+ python/pyspark/pandas/indexes/datetimes.py:22: note: Error code "import" not covered by "type: ignore" comment
+ python/pyspark/pandas/indexes/category.py:20: note: Error code "import" not covered by "type: ignore" comment
+ python/pyspark/pandas/namespace.py:44: note: Error code "import" not covered by "type: ignore" comment
+ python/pyspark/pandas/plot/matplotlib.py:26: note: Error code "import" not covered by "type: ignore" comment
+ python/pyspark/pandas/data_type_ops/num_ops.py:23: note: Error code "import" not covered by "type: ignore" comment
+ python/pyspark/testing/pandasutils.py:27: note: Error code "import" not covered by "type: ignore" comment

pytest (https://github.com/pytest-dev/pytest)
+ src/_pytest/mark/structures.py:405: note: Error code "no-overload-impl" not covered by "type: ignore" comment
+ src/_pytest/mark/structures.py:423: note: Error code "no-overload-impl" not covered by "type: ignore" comment

pip (https://github.com/pypa/pip)
+ src/pip/_internal/utils/logging.py:156: note: Error code "assignment" not covered by "type: ignore" comment

pylox (https://github.com/sco1/pylox)
+ pylox/ast_printer.py:17: note: Error code "arg-type" not covered by "type: ignore" comment

core (https://github.com/home-assistant/core)
+ homeassistant/helpers/entity_platform.py:481: note: Error code changed to literal-required; "type: ignore" comment may be out of date
+ homeassistant/components/co2signal/sensor.py:102: note: Error code changed to literal-required; "type: ignore" comment may be out of date

@JukkaL JukkaL merged commit 99f4d5a into master Jan 25, 2022
@JukkaL JukkaL deleted the error-code-note branch January 25, 2022 16:54
PeterJCLaw added a commit to PeterJCLaw/mypy that referenced this pull request Feb 9, 2022
This appears to have originated in python#12067
which was picked up by 61e9589.

TODO: Work out if we should minimise the number of errors that users
end up with in this scenario.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants