Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Merged

Conversation

@ilevkivskyi
Copy link
Member

@ilevkivskyiilevkivskyi commentedJun 14, 2025
edited
Loading

Fixes#9815
Fixes#10848
Fixes#17781

Also discovered this while working oncheckmember 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).

@ilevkivskyi
Copy link
MemberAuthor

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

@github-actions

This comment has been minimized.

def __init__(self) -> None: ...
class C(B): ...

reveal_type(C) # N: Revealed type is "def () -> __main__.C"
Copy link
Collaborator

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?

@github-actions
Copy link
Contributor

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]

@ilevkivskyiilevkivskyi merged commitd52ce3b intopython:masterJun 18, 2025
19 checks passed
@ilevkivskyiilevkivskyi deleted the correct-constructor-any branchJune 18, 2025 23:26
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@JukkaLJukkaLJukkaL approved these changes

+1 more reviewer

@sterliakovsterliakovsterliakov approved these changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

3 participants

@ilevkivskyi@JukkaL@sterliakov

[8]ページ先頭

©2009-2025 Movatter.jp