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

Allow function arguments as base classes#14135

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
ilevkivskyi merged 4 commits intopython:masterfromilevkivskyi:allow-arg-bases
Nov 21, 2022

Conversation

@ilevkivskyi
Copy link
Member

@ilevkivskyiilevkivskyi commentedNov 18, 2022
edited
Loading

Fixes#5865

Looks quite easy and safe, unless I am missing something. Most changes in the diff are just moving stuff around.

Previously we only applied argument types before type checking, but it looks like we can totally do this in semantic analyzer. I also enable variable annotated astype (or equivalentlyType[Any]), this use case was mentioned in the comments.

This PR also accidentally fixes two additional bugs, one related to type variables with values vs walrus operator, another one for type variables with values vs self types. I include test cases for those as well.

maxbane reacted with hooray emoji
@github-actions

This comment has been minimized.

@ilevkivskyi
Copy link
MemberAuthor

Thehomeassistant errors are caused by exposing an existing bug in walrus. On master this test

[case testNarrowOnSelfInGeneric]# flags: --strict-optionalfrom typing import Generic, TypeVar, OptionalT = TypeVar("T", int, str)class C(Generic[T]):    x: Optional[T]    def meth(self) -> Optional[T]:        if (y := self.x) is not None:            return reveal_type(y)        return None

reveals typeAny. But with this PR it becomes optional, so it is still wrong. I will first try to figure out what is going on.

@ilevkivskyi
Copy link
MemberAuthor

OK, I have a fix for the walrus bug, since it is an obvious bug, I am going to just add it to this PR.

@github-actions

This comment has been minimized.

@ilevkivskyi
Copy link
MemberAuthor

Looking again atmypy_primer it looks like this PR accidental fixes another bug related to type vars with values, this type for self types. I am going to include a regression for that one as well.

@github-actions
Copy link
Contributor

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

artigraph (https://github.com/artigraph/artigraph)+ tests/arti/producers/test_producer.py:679: error: Unused "type: ignore" comment+ tests/arti/producers/test_producer.py:680: error: Unused "type: ignore" commentTanjun (https://github.com/FasterSpeeding/Tanjun)- tanjun/dependencies/reloaders.py:566: error: Cannot determine type of "real_path"  [has-type]- tanjun/dependencies/reloaders.py:567: error: Cannot determine type of "time"  [has-type]- tanjun/dependencies/reloaders.py:578: error: Cannot determine type of "info"  [has-type]- tanjun/dependencies/reloaders.py:579: error: Cannot determine type of "time"  [has-type]- tanjun/dependencies/reloaders.py:599: error: Cannot determine type of "path"  [has-type]- tanjun/dependencies/reloaders.py:600: error: Cannot determine type of "tracked_value"  [has-type]- tanjun/dependencies/reloaders.py:609: error: Cannot determine type of "path"  [has-type]- tanjun/dependencies/reloaders.py:609: error: Cannot determine type of "path_info"  [has-type]- tanjun/commands/menu.py:580: error: Incompatible return value type (got "MenuCommand[_MenuCommandCallbackSigT, _MenuTypeT]", expected "Self")  [return-value]mypy (https://github.com/python/mypy)+ mypy/stubtest.py:357: error: Unused "type: ignore[valid-type]" commentcloud-init (https://github.com/canonical/cloud-init)+ cloudinit/templater.py:44: error: Unused "type: ignore" comment

Copy link
Collaborator

@JukkaLJukkaL left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Nice -- fixing three bugs for the price of one!

I can't see why setting the argument types in the semantic analyzer would be a problem.

Left a comment that is mostly unrelated to this PR, feel free to ignore it if you are not sure.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@JukkaLJukkaLJukkaL approved these changes

@JelleZijlstraJelleZijlstraAwaiting requested review from JelleZijlstra

@hauntsaninjahauntsaninjaAwaiting requested review from hauntsaninja

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Function argument rejected as a base class

2 participants

@ilevkivskyi@JukkaL

[8]ページ先頭

©2009-2025 Movatter.jp