Repository navigation
Add missing function attributes to builtins.function - #6804
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 <Alex.Waygood@Gmail.com>
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
|
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 <Alex.Waygood@Gmail.com>
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
|
Follow up PR to #6803. In that PR we tried getting
builtins.functionto share attributes/methods withtypes.FunctionTypebut it didn't work. Instead I'm just manually adding the missing attributes tobuiltins.functionto resolve this issue: python/mypy#11896 (comment)Changes:
@finaldecorator tobuiltins.function.types.FunctionTypetobuiltins.function.__get__method fromtypes.FunctionTypetobuiltins.function.builtins.function.__get__toAnyto account for property and getset_descriptor returns.