Skip to content

Fix constructor type for subclasses of Any #19295

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ilevkivskyi
Copy link
Member

@ilevkivskyi ilevkivskyi commented Jun 14, 2025

Fixes #9815
Fixes #10848
Fixes #17781

Also discovered this while working on checkmember stuff. Previously, return type of the type object was the class where __init__() was defined (if there was an Any somewhere in MRO). And since we use return type for attribute access on type objects, it went completely sideways. Fix is simple (we accidentally used info instead of def_info in one place).

@ilevkivskyi
Copy link
Member Author

The fix here is quite trivial, so I will probably not wait for a review unless there are objections. cc @JukkaL

Copy link
Contributor

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

poetry (https://github.com/python-poetry/poetry)
- src/poetry/console/commands/self/show/__init__.py:41: error: Returning Any from function declared to return "set[NormalizedName]"  [no-any-return]

prefect (https://github.com/PrefectHQ/prefect)
- src/prefect/logging/loggers.py:144: error: Unused "type: ignore" comment  [unused-ignore]
- src/prefect/utilities/hashing.py:74: error: Argument 1 to "dumps" of "Serializer" has incompatible type "tuple[tuple[Any, ...], dict[str, Any]]"; expected "D"  [arg-type]
- src/prefect/context.py:829: error: Item "None" of "Optional[ContextModel]" has no attribute "current_tags"  [union-attr]
- src/prefect/tasks.py:930: error: Item "None" of "Optional[ContextModel]" has no attribute "current_tags"  [union-attr]
- src/prefect/tasks.py:1047: error: Item "None" of "Optional[ContextModel]" has no attribute "current_tags"  [union-attr]
+ src/prefect/tasks.py:1297: error: Argument 1 to "submit" of "TaskRunner" has incompatible type "Union[Task[P, R], Task[P, Coroutine[Any, Any, R]]]"; expected "Task[P, Coroutine[Any, Any, R]]"  [arg-type]
+ src/prefect/tasks.py:1297: error: Argument 3 to "submit" of "TaskRunner" has incompatible type "Optional[Union[Union[PrefectFuture[Any], Any], Iterable[Union[PrefectFuture[Any], Any]]]]"; expected "Optional[Iterable[PrefectFuture[Any]]]"  [arg-type]
- src/prefect/flow_engine.py:521: error: Item "None" of "Optional[ContextModel]" has no attribute "current_tags"  [union-attr]
- src/prefect/flow_engine.py:1084: error: Item "None" of "Optional[ContextModel]" has no attribute "current_tags"  [union-attr]
+ src/prefect/task_engine.py:985: error: Item "None" of "Optional[FlowRun]" has no attribute "run_count"  [union-attr]
- src/prefect/workers/base.py:838: error: Item "None" of "Optional[ContextModel]" has no attribute "current_tags"  [union-attr]
+ src/prefect/runtime/flow_run.py:140: error: Item "None" of "Optional[FlowRun]" has no attribute "id"  [union-attr]
+ src/prefect/runtime/flow_run.py:159: error: Item "None" of "Optional[FlowRun]" has no attribute "tags"  [union-attr]
+ src/prefect/runtime/flow_run.py:174: error: Item "None" of "Optional[FlowRun]" has no attribute "run_count"  [union-attr]
+ src/prefect/runtime/flow_run.py:189: error: Item "None" of "Optional[FlowRun]" has no attribute "name"  [union-attr]
+ src/prefect/runtime/flow_run.py:204: error: Item "None" of "Optional[Flow[Any, Any]]" has no attribute "name"  [union-attr]
+ src/prefect/runtime/flow_run.py:219: error: Item "None" of "Optional[Flow[Any, Any]]" has no attribute "version"  [union-attr]
+ src/prefect/runtime/flow_run.py:234: error: Item "None" of "Optional[FlowRun]" has no attribute "expected_start_time"  [union-attr]
+ src/prefect/runtime/flow_run.py:242: error: Incompatible return value type (got "Optional[dict[str, Any]]", expected "dict[str, Any]")  [return-value]
+ src/prefect/runtime/flow_run.py:257: error: Item "None" of "Optional[FlowRun]" has no attribute "parent_task_run_id"  [union-attr]
+ src/prefect/runtime/flow_run.py:334: error: Item "None" of "Optional[FlowRun]" has no attribute "job_variables"  [union-attr]
+ src/prefect/flow_runs.py:279: error: Item "None" of "Optional[FlowRun]" has no attribute "id"  [union-attr]
+ src/prefect/flow_runs.py:315: error: Item "None" of "Optional[FlowRun]" has no attribute "id"  [union-attr]
+ src/prefect/deployments/flow_runs.py:154: error: Item "None" of "Optional[FlowRun]" has no attribute "id"  [union-attr]
- src/prefect/deployments/flow_runs.py:156: error: Item "None" of "Optional[RunContext]" has no attribute "task_run"  [union-attr]
+ src/prefect/deployments/flow_runs.py:156: error: Item "None" of "Optional[TaskRunContext]" has no attribute "task_run"  [union-attr]
- src/prefect/deployments/flow_runs.py:161: error: Item "None" of "Optional[RunContext]" has no attribute "task_run"  [union-attr]
+ src/prefect/deployments/flow_runs.py:161: error: Item "None" of "Optional[TaskRunContext]" has no attribute "task_run"  [union-attr]

kornia (https://github.com/kornia/kornia)
- kornia/augmentation/container/ops.py:496: error: Unused "type: ignore" comment  [unused-ignore]

zulip (https://github.com/zulip/zulip)
+ zerver/tests/test_auth_backends.py:469: error: Cannot assign to a method  [method-assign]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant