-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix
functools.cache
and operator.attrgetter
- Loading branch information
1 parent
8cd497f
commit a8d99fe
Showing
10 changed files
with
101 additions
and
60 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Empty file.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from __future__ import annotations | ||
|
||
from functools import lru_cache | ||
|
||
# use `basedtyping` when we drop python 3.8 | ||
from types import MethodType | ||
from typing import TYPE_CHECKING, Callable | ||
from typing_extensions import assert_type | ||
|
||
from mypy_extensions import Arg | ||
|
||
# use `functools.cache` when we drop python 3.8 | ||
cache = lru_cache(None) | ||
|
||
|
||
class A: | ||
@cache | ||
def m(self, a: list[int]): ... | ||
|
||
@classmethod | ||
@cache | ||
def c(cls, a: list[int]): ... | ||
|
||
@staticmethod | ||
@cache | ||
def s(a: list[int]): ... | ||
|
||
|
||
@cache | ||
def f(a: list[int]): ... | ||
|
||
|
||
if TYPE_CHECKING: | ||
from functools import _HashCallable, _LruCacheWrapperBase, _LruCacheWrapperMethod | ||
|
||
ExpectedFunction = _LruCacheWrapperBase[Callable[[Arg(list[int], "a")], None]] | ||
ExpectedMethod = _LruCacheWrapperMethod[Callable[[Arg(list[int], "a")], None]] | ||
ExpectedMethodNone = _LruCacheWrapperMethod["() -> None"] | ||
a = A() | ||
a.m([1]) # type: ignore[arg-type] | ||
assert_type(a.m, ExpectedMethod) | ||
assert_type(a.c, ExpectedMethod) | ||
# this is wrong, it shouldn't eat the `a` argument, but this is because of mypy `staticmethod` special casing | ||
assert_type(a.s, ExpectedMethodNone) | ||
assert_type(a.s, MethodType & (_LruCacheWrapperBase[Callable[[Arg(list[int], "a")], None]] | _HashCallable)) # type: ignore[assert-type] | ||
assert_type(f.__get__(1), ExpectedMethodNone) | ||
f([1]) # type: ignore[arg-type] |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from operator import attrgetter | ||
from typing_extensions import assert_type | ||
|
||
|
||
def check_attrgetter(): | ||
assert_type(attrgetter("name"), attrgetter[object]) |
This file was deleted.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
This file contains 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