-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Dmypy 418 #18942
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
base: master
Are you sure you want to change the base?
Dmypy 418 #18942
Conversation
Diff from mypy_primer, showing the effect of this PR on open source code: kornia (https://github.com/kornia/kornia)
+ kornia/core/mixin/image_module.py:113: error: Unused "type: ignore" comment [unused-ignore]
+ kornia/core/mixin/image_module.py:115: error: Unused "type: ignore" comment [unused-ignore]
+ kornia/core/mixin/image_module.py:137: error: Unused "type: ignore" comment [unused-ignore]
+ kornia/core/mixin/image_module.py:141: error: Unused "type: ignore" comment [unused-ignore]
+ kornia/core/mixin/image_module.py:157: error: Unused "type: ignore" comment [unused-ignore]
+ kornia/core/mixin/image_module.py:159: error: Unused "type: ignore" comment [unused-ignore]
+ kornia/core/mixin/image_module.py:183: error: Unused "type: ignore" comment [unused-ignore]
+ kornia/core/mixin/image_module.py:185: error: Unused "type: ignore" comment [unused-ignore]
+ kornia/core/module.py:119: error: Unused "type: ignore" comment [unused-ignore]
+ kornia/core/module.py:121: error: Unused "type: ignore" comment [unused-ignore]
+ kornia/core/module.py:141: error: Unused "type: ignore" comment [unused-ignore]
+ kornia/core/module.py:143: error: Unused "type: ignore" comment [unused-ignore]
+ kornia/core/module.py:159: error: Unused "type: ignore" comment [unused-ignore]
+ kornia/core/module.py:161: error: Unused "type: ignore" comment [unused-ignore]
+ kornia/core/module.py:185: error: Unused "type: ignore" comment [unused-ignore]
+ kornia/core/module.py:187: error: Unused "type: ignore" comment [unused-ignore]
+ kornia/core/mixin/onnx.py:307: error: Unused "type: ignore" comment [unused-ignore]
hydpy (https://github.com/hydpy-dev/hydpy)
+ hydpy/cythons/modelutils.py:379: error: Unused "type: ignore" comment [unused-ignore]
pydantic (https://github.com/pydantic/pydantic)
+ pydantic/v1/typing.py:483: error: Unused "type: ignore" comment [unused-ignore]
+ pydantic/v1/utils.py:176: error: Unused "type: ignore" comment [unused-ignore]
+ pydantic/v1/utils.py:183: error: Unused "type: ignore" comment [unused-ignore]
+ pydantic/v1/class_validators.py:356: error: Unused "type: ignore[arg-type, var-annotated]" comment [unused-ignore]
+ pydantic/v1/fields.py:666: error: Unused "type: ignore" comment [unused-ignore]
+ pydantic/v1/fields.py:743: error: Unused "type: ignore" comment [unused-ignore]
+ pydantic/v1/schema.py:1081: error: Unused "type: ignore" comment [unused-ignore]
+ pydantic/_internal/_utils.py:97: error: Unused "type: ignore" comment [unused-ignore]
- pydantic/_internal/_generate_schema.py:1240: error: Argument 2 to "isinstance" has incompatible type "<typing special form>"; expected "_ClassInfo" [arg-type]
- pydantic/_internal/_generate_schema.py:1291: error: Argument 2 to "isinstance" has incompatible type "<typing special form>"; expected "_ClassInfo" [arg-type]
- pydantic/main.py:576: error: Argument 2 to "issubclass" has incompatible type "<typing special form>"; expected "_ClassInfo" [arg-type]
- pydantic/dataclasses.py:234: error: Argument 2 to "issubclass" has incompatible type "<typing special form>"; expected "_ClassInfo" [arg-type]
dacite (https://github.com/konradhalas/dacite)
+ dacite/types.py:180: error: Unused "type: ignore" comment [unused-ignore]
schemathesis (https://github.com/schemathesis/schemathesis)
+ src/schemathesis/cli/ext/options.py: note: In member "convert" of class "CsvEnumChoice":
+ src/schemathesis/cli/ext/options.py:61: error: Item "list[str]" of "Union[Any, str, list[str]]" has no attribute "upper" [union-attr]
+ src/schemathesis/cli/ext/options.py: note: At top level:
spark (https://github.com/apache/spark)
+ python/pyspark/ml/functions.py:798: error: Unused "type: ignore" comment [unused-ignore]
Tanjun (https://github.com/FasterSpeeding/Tanjun)
+ tanjun/clients.py:3179: error: Returning Any from function declared to return Module [no-any-return]
operator (https://github.com/canonical/operator)
- ops/lib/__init__.py:274: error: Incompatible types in assignment (expression has type Module, variable has type "None") [assignment]
hydra-zen (https://github.com/mit-ll-responsible-ai/hydra-zen)
- src/hydra_zen/structured_configs/_implementations.py:2846: error: Incompatible types in assignment (expression has type "tuple[str, Any, Any]", variable has type "tuple[str, Any]") [assignment]
+ src/hydra_zen/structured_configs/_implementations.py:2846: error: Incompatible types in assignment (expression has type "tuple[Any, Any, Any]", variable has type "tuple[Any, Any]") [assignment]
- src/hydra_zen/structured_configs/_implementations.py:2847: error: Argument 1 to "append" of "list" has incompatible type "tuple[str, Any]"; expected "tuple[str, type, Field[Any]]" [arg-type]
+ src/hydra_zen/structured_configs/_implementations.py:2847: error: Argument 1 to "append" of "list" has incompatible type "tuple[Any, Any]"; expected "tuple[str, type, Field[Any]]" [arg-type]
sympy (https://github.com/sympy/sympy)
+ sympy/parsing/mathematica.py:895: error: Unused "type: ignore" comment [unused-ignore]
nox (https://github.com/wntrblm/nox)
+ nox/sessions.py:1169: error: Returning Any from function declared to return "str" [no-any-return]
+ nox/tasks.py:84: error: Returning Any from function declared to return Module [no-any-return]
discord.py (https://github.com/Rapptz/discord.py)
- discord/ext/commands/converter.py:1280: error: Argument 2 to "issubclass" has incompatible type "<typing special form>"; expected "_ClassInfo" [arg-type]
- discord/ext/commands/parameters.py:322: error: Incompatible types in assignment (expression has type "OrderedDict[str, discord.ext.commands.parameters.Parameter]", base class "Signature" defined the type as "MappingProxyType[str, inspect.Parameter]") [assignment]
- discord/ext/commands/cog.py:244: error: Argument 1 to "list" has incompatible type "dict_values[str, _BaseCommand]"; expected "Iterable[Command[Any, [VarArg(Any), KwArg(Any)], Any]]" [arg-type]
+ discord/ext/commands/cog.py:244: error: Argument 1 to "list" has incompatible type "dict_values[Any, _BaseCommand]"; expected "Iterable[Command[Any, [VarArg(Any), KwArg(Any)], Any]]" [arg-type]
+ discord/ext/commands/hybrid.py:206: error: Unused "type: ignore" comment [unused-ignore]
dd-trace-py (https://github.com/DataDog/dd-trace-py)
+ ddtrace/debugging/_function/discovery.py:81: error: Unused "type: ignore" comment [unused-ignore]
+ ddtrace/debugging/_function/discovery.py:92: error: Unused "type: ignore" comment [unused-ignore]
pandera (https://github.com/pandera-dev/pandera)
+ pandera/api/dataframe/components.py:199: error: Unused "type: ignore" comment [unused-ignore]
ibis (https://github.com/ibis-project/ibis)
- ibis/expr/operations/udf.py:144: error: Dict entry 1 has incompatible type "str": "InputType"; expected "str": "Argument" [dict-item]
+ ibis/expr/operations/udf.py:144: error: Dict entry 1 has incompatible type "str": "InputType"; expected "Any": "Argument" [dict-item]
- ibis/expr/operations/udf.py:147: error: Dict entry 2 has incompatible type "str": "property"; expected "str": "Argument" [dict-item]
+ ibis/expr/operations/udf.py:147: error: Dict entry 2 has incompatible type "str": "property"; expected "Any": "Argument" [dict-item]
- ibis/expr/operations/udf.py:148: error: Dict entry 3 has incompatible type "str": "FrozenDict[Never, Never]"; expected "str": "Argument" [dict-item]
+ ibis/expr/operations/udf.py:148: error: Dict entry 3 has incompatible type "str": "FrozenDict[Never, Never]"; expected "Any": "Argument" [dict-item]
- ibis/expr/operations/udf.py:149: error: Dict entry 4 has incompatible type "str": "Namespace"; expected "str": "Argument" [dict-item]
+ ibis/expr/operations/udf.py:149: error: Dict entry 4 has incompatible type "str": "Namespace"; expected "Any": "Argument" [dict-item]
- ibis/expr/operations/udf.py:150: error: Dict entry 5 has incompatible type "str": "str"; expected "str": "Argument" [dict-item]
+ ibis/expr/operations/udf.py:150: error: Dict entry 5 has incompatible type "str": "str"; expected "Any": "Argument" [dict-item]
- ibis/expr/operations/udf.py:151: error: Dict entry 6 has incompatible type "str": "str"; expected "str": "Argument" [dict-item]
+ ibis/expr/operations/udf.py:151: error: Dict entry 6 has incompatible type "str": "str"; expected "Any": "Argument" [dict-item]
core (https://github.com/home-assistant/core)
+ homeassistant/components/python_script/__init__.py:181: error: Returning Any from function declared to return Module [no-any-return]
mitmproxy (https://github.com/mitmproxy/mitmproxy)
+ mitmproxy/addons/script.py:40: error: Unused "type: ignore" comment [unused-ignore]
beartype (https://github.com/beartype/beartype)
+ beartype/_util/cls/utilclsget.py:167: error: Unused "type: ignore" comment [unused-ignore]
+ beartype/_util/hint/pep/proposal/pep544.py:133: error: Unused "type: ignore" comment [unused-ignore]
+ beartype/_util/cls/pep/clspep3119.py:90: error: Unused "type: ignore" comment [unused-ignore]
+ beartype/_util/cls/pep/clspep3119.py:766: error: Unused "type: ignore" comment [unused-ignore]
pyodide (https://github.com/pyodide/pyodide)
+ src/py/_pyodide/docstring.py:45: error: Unused "type: ignore" comment [unused-ignore]
pytest (https://github.com/pytest-dev/pytest)
+ src/_pytest/pathlib.py:733: error: Returning Any from function declared to return "Optional[Module]" [no-any-return]
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume you accidentally committed a bunch of files? The lxml changes and the std_types
changes are not necessary and shouldn't be in this PR. (and changing our vendored typeshed is a very bad idea)
I also would prefer another implementation.
@@ -213,7 +213,7 @@ generic types or your own type aliases), look through the | |||
|
|||
.. note:: | |||
|
|||
When adding types, the convention is to import types | |||
When adding types, the convention is to import types as std_types |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is talking about importing typing
and this isn't the convention.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, the convention is "never alias-import stdlib modules unless strictly necessary". Please revert this doc change along with all imports garbled in other files.
@@ -653,7 +652,7 @@ def extract_from_decorator(self, node: Decorator) -> FuncDef | None: | |||
for ct in typ.items: | |||
if not ( | |||
len(ct.arg_types) == 1 | |||
and isinstance(ct.arg_types[0], TypeVarType) | |||
# and isinstance(ct.arg_types[0], TypeVarType) | |||
and ct.arg_types[0] == ct.ret_type | |||
): | |||
return None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looks like a special case for this decorator:
def f(x: T) -> T:
return x
you should add a special case in addition to this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, technically this line is limiting to that special case. And this will even fix the linked issue, two callables of that shape will compare equal AFAIC.
But this also makes the following (completely wrong) deco generate a signature:
def deco(fn: str) -> str: ...
@deco
def foo():
print()
So I agree there should be one more special case, not just blanket "one-arg function returning its arg unchanged".
@@ -653,7 +652,7 @@ def extract_from_decorator(self, node: Decorator) -> FuncDef | None: | |||
for ct in typ.items: | |||
if not ( | |||
len(ct.arg_types) == 1 | |||
and isinstance(ct.arg_types[0], TypeVarType) | |||
# and isinstance(ct.arg_types[0], TypeVarType) | |||
and ct.arg_types[0] == ct.ret_type | |||
): | |||
return None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, technically this line is limiting to that special case. And this will even fix the linked issue, two callables of that shape will compare equal AFAIC.
But this also makes the following (completely wrong) deco generate a signature:
def deco(fn: str) -> str: ...
@deco
def foo():
print()
So I agree there should be one more special case, not just blanket "one-arg function returning its arg unchanged".
@@ -213,7 +213,7 @@ generic types or your own type aliases), look through the | |||
|
|||
.. note:: | |||
|
|||
When adding types, the convention is to import types | |||
When adding types, the convention is to import types as std_types |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, the convention is "never alias-import stdlib modules unless strictly necessary". Please revert this doc change along with all imports garbled in other files.
@@ -2075,7 +2075,7 @@ class F: | |||
def g(): ... | |||
|
|||
[case testCoroutineImportTypesAsT] | |||
import types as t | |||
import types as std_types as t |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sed
is great, but this isn't even valid python.
Fixes #18940 (hopefully; I wrote a test, but I'm having trouble running it)
How this PR changes mypy:
Deleted the line mentioned in the original issue, added an import called "types", and made a few other small changes.
I think there's a problem with the test I wrote. For some reason, when I type dmypy check ., it says Daemon has died. For the sake of my team's academic assignment, I'd like to label this as a work in progress tentatively, then return to it later because I can't let anyone else claim it for now.