-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Using "attrgetter" as a parameter in sorted() method produces an error #2383
Comments
Hmm... That's an interesting one! Why are you using That said, the reason it works with (I think it should have worked with the definition from The problem with avoiding false negatives for attrgetter is that unless we special-case It's similar for functools.partial: #1484. It's also similar for getattr. Example: class C:
def __init__(self) -> None:
self.x = 12
c = C()
x = c.x
y = getattr(c, 'x')
reveal_type(x) # Revealed type is 'builtins.int'
reveal_type(y) # Revealed type is 'Any' |
Does PyDev get that information from typeshed or from somewhere else?
|
PyDev knows nothing about typeshed. (Based on https://github.com/fabioz/Pydev/search?utf8=%E2%9C%93&q=typeshed ) |
OK, then PyDev should learn not to suggest the builtin module corresponding
to a .py module -- this would probably cause confusion for many other such
module pairs (e.g. _pickle, _heapq, who knows what else, it's a common
pattern).
There's still the mypy issue with attrgetter of course. (And we should
probably delete the `_operator` module -- or fix it so it's identical to
operator?)
|
Maybe mypy should show a warning when a module like _operator is imported. |
How would you configure which imports deserve warnings?
|
This module can be deprecated somehow and warning can be shown for all deprecated modules. |
Anyway, if mypy checks types, it should be able to check deprecations as well. |
I've got a feeling there's something missing. Maybe you could try to come up with a PR to see if you can make something that works. |
Can you create a new issue about deprecated modules first? It's a separate issue from this, at least as it was originally reported, and it's confusing to mix two discussions. |
Here is the issue about deprecation |
The original issue is due to typeshed (created an issue: python/typeshed#835) so closing this now. |
When using attrgetter as a key to sorted(), mypy treats attrgetter as a type, not as sorted() second parameter. Although when using lambda as a key, mypy doesn't treat it that way.
Here's what I get when I try to type check the code above:
The text was updated successfully, but these errors were encountered: