-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Handle assignment of bound methods in class bodies #19233
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
Conversation
This comment has been minimized.
This comment has been minimized.
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.
Nice! The mypy primer error message change in mongo-python-driver
looks odd though -- do you know what is going on there?
@@ -11217,3 +11217,27 @@ class A: | |||
[out] | |||
== | |||
main:3: error: Property "f" defined in "A" is read-only | |||
|
|||
[case testMethodMakeBoundFineGrained] |
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.
Add also normal incremental mode (serialization) tests case?
x1 = A.f | ||
x2 = A.g | ||
x3 = A().f | ||
x4 = A().g |
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.
Would it make sense to test @staticmethod
as well?
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.
And maybe normal attribute with an explicit annotated Callable
type?
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.
Static methods are actually unrelated to this story, they are already handled using special-casing here https://github.com/python/mypy/blob/master/mypy/checker.py#L4420-L4422. But I still added the tests, because existing tests only cover static method alias within same class. (Also attributes with explicit callable annotations are considered instance attributes, but anyway added for completeness.)
Yes, the same thing that is going on in |
Diff from mypy_primer, showing the effect of this PR on open source code: prefect (https://github.com/PrefectHQ/prefect)
- src/prefect/_internal/concurrency/threads.py:37: error: Attribute function "_counter" with type "Callable[[], int]" does not accept self argument [misc]
jinja (https://github.com/pallets/jinja)
+ src/jinja2/runtime.py:370: error: Unused "type: ignore" comment [unused-ignore]
+ src/jinja2/runtime.py:384: error: Unused "type: ignore" comment [unused-ignore]
+ src/jinja2/environment.py:1290: error: Unused "type: ignore" comment [unused-ignore]
+ src/jinja2/environment.py:1311: error: Unused "type: ignore" comment [unused-ignore]
mongo-python-driver (https://github.com/mongodb/mongo-python-driver)
- pymongo/synchronous/cursor.py:1004: error: Invalid index type "int | Any | Pattern[Any]" for "list[Any]"; expected type "SupportsIndex" [index]
+ pymongo/synchronous/cursor.py:1004: error: Invalid index type "int | Any | Pattern[Any]" for "list"; expected type "SupportsIndex" [index]
- pymongo/asynchronous/cursor.py:1006: error: Invalid index type "int | Any | Pattern[Any]" for "list[Any]"; expected type "SupportsIndex" [index]
+ pymongo/asynchronous/cursor.py:1006: error: Invalid index type "int | Any | Pattern[Any]" for "list"; expected type "SupportsIndex" [index]
|
Thanks! |
Fixes #18438
Fixes #19146
Surprisingly, a very small change is sufficient to replicate Python runtime behavior for all the important cases (see
checkmember.py
). I also replace thebound_args
argument ofCallableType
, that was mostly unused, with a flag (as suggested by @JukkaL) and make sure it is properly set/preserved everywhere.