Add note about wrong error code in type: ignore#12067
Merged
Merged
Conversation
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.
Member
|
Would it make sense to just always print this note if we detect a |
This comment has been minimized.
This comment has been minimized.
Collaborator
Author
|
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. |
jhance
approved these changes
Jan 25, 2022
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
|
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.