Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork3.1k
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
ilevkivskyi commentedJun 14, 2025
The fix here is quite trivial, so I will probably not wait for a review unless there are objections. cc@JukkaL |
This comment has been minimized.
This comment has been minimized.
| def __init__(self) -> None: ... | ||
| class C(B): ... | ||
| reveal_type(C) # N: Revealed type is "def () -> __main__.C" |
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.
What about also testing a generic class that subclassesAny?
Diff frommypy_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] |
d52ce3b intopython:masterUh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Fixes#9815
Fixes#10848
Fixes#17781
Also discovered this while working on
checkmemberstuff. Previously, return type of the type object was the class where__init__()was defined (if there was anAnysomewhere in MRO). And since we use return type for attribute access on type objects, it went completely sideways. Fix is simple (we accidentally usedinfoinstead ofdef_infoin one place).