-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Add missing function attributes to builtins.function #6804
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.
Could you try copying over the |
I also notice that |
Neither But obviously this is a really weird class that doesn't actually exist, and is only here because of a weird mypy implementation detail that says it has to exist. So maybe deleting |
This comment has been minimized.
This comment has been minimized.
Co-authored-by: Alex Waygood <[email protected]>
Co-authored-by: Alex Waygood <[email protected]>
I'd argue the proper response to the failing stubtest checks would be to add entries to https://github.com/python/typeshed/blob/master/tests/stubtest_allowlists/py3_common.txt for |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@AlexWaygood agree with you. A single argument in >>> class Foo: ...
...
>>> def bar(self): print("hi")
...
>>> bar.__get__(Foo)
<bound method bar of <class '__main__.Foo'>>
>>> bar.__get__(Foo)()
hi |
The Unused type imports in mypy_primer are a good sign that this fixes some mypy issues. For this one I think it's a mistake in urllib3 rather than a mypy issue:
https://github.com/urllib3/urllib3/blob/fd2759aa16b12b33298900c77d29b3813c6582de/src/urllib3/response.py#L773 |
This comment has been minimized.
This comment has been minimized.
will try this now 👍 |
This comment has been minimized.
This comment has been minimized.
On the other hand: >>> object().__module__
Traceback (most recent call last):
File "<string>", line 1, in <module>
AttributeError: 'object' object has no attribute '__module__' So, even though it does now, it's questionable whether Maybe it would be best to leave the |
edcc416
to
a1ab18f
Compare
This comment has been minimized.
This comment has been minimized.
hold off on merging for a sec, just want to check something quickly on the get method |
I don't have the power to merge, don't worry 😄 |
So the Currently we have However this doesn't account for the fact that this method could be a property. Consider this script: class Foo:
def __init__(self) -> None: ...
def bar(self) -> str:
return "bar"
@property
def baz(self) -> str:
return "baz"
class OtherClass:
def __init__(self) -> None: ...
if __name__ == "__main__":
foo = Foo()
print(type(foo.bar))
print(type(foo.baz))
other_class = OtherClass()
print(type(Foo.bar.__get__(other_class)))
print(type(Foo.baz.__get__(other_class))) This prints:
So Think I should drop the |
Personally, I see nothing wrong with including it in this PR (but, I'm not a maintainer, just a contributor). The PR is about false-positive mypy errors for function attributes, and I agree that it would be good to change the return type to |
urllib3 is correct. Because
Here's an example with a preoperty:
IMO the best solution would be to return |
...and I just realized that you already realized this, nevermind :) |
Co-authored-by: Alex Waygood <[email protected]>
This comment has been minimized.
This comment has been minimized.
1 similar comment
This comment has been minimized.
This comment has been minimized.
primer output looks good now 😄 I've added a summary of what's been added to the PR description |
This comment has been minimized.
This comment has been minimized.
1 similar comment
Diff from mypy_primer, showing the effect of this PR on open source code: urllib3 (https://github.com/urllib3/urllib3)
+ src/urllib3/response.py:773: error: Unused "type: ignore[attr-defined]" comment
werkzeug (https://github.com/pallets/werkzeug)
+ src/werkzeug/local.py:283: error: Unused "type: ignore" comment
+ src/werkzeug/routing.py:880: error: Unused "type: ignore" comment
+ src/werkzeug/routing.py:882: error: Unused "type: ignore" comment
|
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.
Thanks!
Follow up PR to #6803. In that PR we tried getting
builtins.function
to share attributes/methods withtypes.FunctionType
but it didn't work. Instead I'm just manually adding the missing attributes tobuiltins.function
to resolve this issue: python/mypy#11896 (comment)Changes:
@final
decorator tobuiltins.function
.types.FunctionType
tobuiltins.function
.__get__
method fromtypes.FunctionType
tobuiltins.function
.builtins.function.__get__
toAny
to account for property and getset_descriptor returns.