Repository navigation
Conversation
Contributor
Author
|
this also (?) appears to fix generics and lru_cache: demofrom typing import TypeVar
from functools import lru_cache
T = TypeVar('T')
@lru_cache(maxsize=5)
def f(x: T) -> T: ...
reveal_type(f)
reveal_type(f.__wrapped__)
reveal_type(f(1))
reveal_type(f('wat'))before$ mypy t.py
t.py:9: note: Revealed type is 'functools._lru_cache_wrapper[T`-1]'
t.py:10: note: Revealed type is 'def (*Any, **Any) -> T`-1'
t.py:11: note: Revealed type is 'T`-1'
t.py:12: note: Revealed type is 'T`-1'after$ mypy t.py --custom-typeshed-dir typeshed
t.py:9: note: Revealed type is 'functools._lru_cache_wrapper[def [T] (x: T`-1) -> T`-1]'
t.py:10: note: Revealed type is 'def [T] (x: T`-1) -> T`-1'
t.py:11: note: Revealed type is 'builtins.int*'
t.py:12: note: Revealed type is 'builtins.str*' |
Contributor
Author
|
ah dang, doesn't work for classes: from functools import lru_cache
class C:
@lru_cache(maxsize=5)
def f(self, x: int) -> int: ...
reveal_type(C().f)
reveal_type(C().f(1))
C().f('wat')$ mypy t.py --custom-typeshed-dir typeshed
t.py:7: note: Revealed type is 'functools._lru_cache_wrapper[def (self: t.C, x: builtins.int) -> builtins.int]'
t.py:8: error: Too few arguments for "f" of "C"
t.py:8: note: Revealed type is 'builtins.int'
t.py:8: error: Argument 1 to "f" of "C" has incompatible type "int"; expected "C"
t.py:9: error: Too few arguments for "f" of "C"
t.py:9: error: Argument 1 to "f" of "C" has incompatible type "str"; expected "C"
Found 4 errors in 1 file (checked 1 source file) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
see also python/mypy#5107
demo file
before
after