-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
ilevkivskyi
wants to merge
1
commit into
python:master
Choose a base branch
from
ilevkivskyi:correct-constructor-any
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
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
The fix here is quite trivial, so I will probably not wait for a review unless there are objections. cc @JukkaL |
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]
|
sterliakov
approved these changes
Jun 15, 2025
JukkaL
approved these changes
Jun 16, 2025
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 subclasses Any
?
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.
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 anAny
somewhere in MRO). And since we use return type for attribute access on type objects, it went completely sideways. Fix is simple (we accidentally usedinfo
instead ofdef_info
in one place).