-
-
Notifications
You must be signed in to change notification settings - Fork 30.5k
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
gh-102444: Fix minor bugs in test_typing
highlighted by pyflakes
#102445
Conversation
def test_hash_eq(self): | ||
self.assertEqual(len({Annotated[int, 4, 5], Annotated[int, 4, 5]}), 1) | ||
self.assertNotEqual(Annotated[int, 4, 5], Annotated[int, 5, 4]) | ||
self.assertNotEqual(Annotated[int, 4, 5], Annotated[str, 4, 5]) | ||
self.assertNotEqual(Annotated[int, 4], Annotated[int, 4, 4]) | ||
self.assertEqual( | ||
{Annotated[int, 4, 5], Annotated[int, 4, 5], Annotated[T, 4, 5]}, | ||
{Annotated[int, 4, 5], Annotated[T, 4, 5]} | ||
) | ||
|
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.
This test is exactly identical to test_hash_eq
on line 7015:
cpython/Lib/test/test_typing.py
Lines 7015 to 7023 in 7894bbe
def test_hash_eq(self): | |
self.assertEqual(len({Annotated[int, 4, 5], Annotated[int, 4, 5]}), 1) | |
self.assertNotEqual(Annotated[int, 4, 5], Annotated[int, 5, 4]) | |
self.assertNotEqual(Annotated[int, 4, 5], Annotated[str, 4, 5]) | |
self.assertNotEqual(Annotated[int, 4], Annotated[int, 4, 4]) | |
self.assertEqual( | |
{Annotated[int, 4, 5], Annotated[int, 4, 5], Annotated[T, 4, 5]}, | |
{Annotated[int, 4, 5], Annotated[T, 4, 5]} | |
) |
@@ -473,7 +473,6 @@ def test_var_substitution(self): | |||
|
|||
def test_bad_var_substitution(self): | |||
T = TypeVar('T') | |||
P = ParamSpec("P") |
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.
P
here is currently an unused variable. ParamSpec.__typing_subst__
is tested in another place in this file:
cpython/Lib/test/test_typing.py
Lines 7528 to 7539 in 7894bbe
def test_bad_var_substitution(self): | |
T = TypeVar('T') | |
P = ParamSpec('P') | |
bad_args = (42, int, None, T, int|str, Union[int, str]) | |
for arg in bad_args: | |
with self.subTest(arg=arg): | |
with self.assertRaises(TypeError): | |
P.__typing_subst__(arg) | |
with self.assertRaises(TypeError): | |
typing.Callable[P, T][arg, str] | |
with self.assertRaises(TypeError): | |
collections.abc.Callable[P, T][arg, str] |
@@ -7515,7 +7499,6 @@ class Y(Generic[P, T]): | |||
self.assertEqual(B.__args__, ((int, str,), Tuple[bytes, float])) | |||
|
|||
def test_var_substitution(self): | |||
T = TypeVar("T") |
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.
T
here is currently an unused variable. TypeVar.__typing_subst__
is tested more fully elsewhere:
cpython/Lib/test/test_typing.py
Lines 461 to 472 in 7894bbe
def test_var_substitution(self): | |
T = TypeVar('T') | |
subst = T.__typing_subst__ | |
self.assertIs(subst(int), int) | |
self.assertEqual(subst(list[int]), list[int]) | |
self.assertEqual(subst(List[int]), List[int]) | |
self.assertEqual(subst(List), List) | |
self.assertIs(subst(Any), Any) | |
self.assertIs(subst(None), type(None)) | |
self.assertIs(subst(T), T) | |
self.assertEqual(subst(int|str), int|str) | |
self.assertEqual(subst(Union[int, str]), Union[int, str]) |
@@ -4918,7 +4913,6 @@ def test_overload_registry_repeated(self): | |||
# Definitions needed for features introduced in Python 3.6 | |||
|
|||
from test import ann_module, ann_module2, ann_module3, ann_module5, ann_module6 | |||
import asyncio |
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.
Typing in Python is definitely synchronous ;)
@@ -1307,7 +1304,7 @@ def test_callable_args_are_correct(self): | |||
i = Callable[[None], *Ts] | |||
j = Callable[[None], Unpack[Ts]] | |||
self.assertEqual(i.__args__, (type(None), *Ts)) | |||
self.assertEqual(i.__args__, (type(None), Unpack[Ts])) | |||
self.assertEqual(j.__args__, (type(None), Unpack[Ts])) |
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.
The j
variable is currently unused. Given the pattern of the assertions immediately below, it seems pretty clear that it was meant to be used here.
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.
Thank you!
Thanks @AlexWaygood for the PR 🌮🎉.. I'm working now to backport this PR to: 3.10, 3.11. |
Sorry, @AlexWaygood, I could not cleanly backport this to |
GH-102451 is a backport of this pull request to the 3.11 branch. |
Thanks for the review @sobolevn! |
…kes (pythonGH-102445) (cherry picked from commit 96e1022) Co-authored-by: Alex Waygood <[email protected]>
…y pyflakes (python#102445) (cherry picked from commit 96e1022)
GH-102452 is a backport of this pull request to the 3.10 branch. |
…H-102445) (cherry picked from commit 96e1022) Co-authored-by: Alex Waygood <[email protected]>
|
This method is identical to `test_hash_eq` on lines 2296-2304: https://github.com/python/typing_extensions/blob/a0858e6ba9b46996f3f74dde8749ab86e1561012/src/test_typing_extensions.py#L2296-L2304 (This is a backport of the only relevant part of python/cpython#102445)
This method is identical to `test_hash_eq` on lines 2296-2304: https://github.com/python/typing_extensions/blob/a0858e6ba9b46996f3f74dde8749ab86e1561012/src/test_typing_extensions.py#L2296-L2304 (This is a backport of the only relevant part of python/cpython#102445)
* main: (21 commits) pythongh-102192: Replace PyErr_Fetch/Restore etc by more efficient alternatives in sub interpreters module (python#102472) pythongh-95672: Fix versionadded indentation of get_pagesize in test.rst (pythongh-102455) pythongh-102416: Do not memoize incorrectly loop rules in the parser (python#102467) pythonGH-101362: Optimise PurePath(PurePath(...)) (pythonGH-101667) pythonGH-101362: Check pathlib.Path flavour compatibility at import time (pythonGH-101664) pythonGH-101362: Call join() only when >1 argument supplied to pathlib.PurePath() (python#101665) pythongh-102444: Fix minor bugs in `test_typing` highlighted by pyflakes (python#102445) pythonGH-102341: Improve the test function for pow (python#102342) Fix unused classes in a typing test (pythonGH-102437) pythongh-101979: argparse: fix a bug where parentheses in metavar argument of add_argument() were dropped (python#102318) pythongh-102356: Add thrashcan macros to filter object dealloc (python#102426) Move around example in to_bytes() to avoid confusion (python#101595) pythonGH-97546: fix flaky asyncio `test_wait_for_race_condition` test (python#102421) pythongh-96821: Add config option `--with-strict-overflow` (python#96823) pythongh-101992: update pstlib module documentation (python#102133) pythongh-63301: Set exit code when tabnanny CLI exits on error (python#7699) pythongh-101863: Fix wrong comments in EUC-KR codec (pythongh-102417) pythongh-102302 Micro-optimize `inspect.Parameter.__hash__` (python#102303) pythongh-102179: Fix `os.dup2` error reporting for negative fds (python#102180) pythongh-101892: Fix `SystemError` when a callable iterator call exhausts the iterator (python#101896) ...
* main: (37 commits) pythongh-102192: Replace PyErr_Fetch/Restore etc by more efficient alternatives in sub interpreters module (python#102472) pythongh-95672: Fix versionadded indentation of get_pagesize in test.rst (pythongh-102455) pythongh-102416: Do not memoize incorrectly loop rules in the parser (python#102467) pythonGH-101362: Optimise PurePath(PurePath(...)) (pythonGH-101667) pythonGH-101362: Check pathlib.Path flavour compatibility at import time (pythonGH-101664) pythonGH-101362: Call join() only when >1 argument supplied to pathlib.PurePath() (python#101665) pythongh-102444: Fix minor bugs in `test_typing` highlighted by pyflakes (python#102445) pythonGH-102341: Improve the test function for pow (python#102342) Fix unused classes in a typing test (pythonGH-102437) pythongh-101979: argparse: fix a bug where parentheses in metavar argument of add_argument() were dropped (python#102318) pythongh-102356: Add thrashcan macros to filter object dealloc (python#102426) Move around example in to_bytes() to avoid confusion (python#101595) pythonGH-97546: fix flaky asyncio `test_wait_for_race_condition` test (python#102421) pythongh-96821: Add config option `--with-strict-overflow` (python#96823) pythongh-101992: update pstlib module documentation (python#102133) pythongh-63301: Set exit code when tabnanny CLI exits on error (python#7699) pythongh-101863: Fix wrong comments in EUC-KR codec (pythongh-102417) pythongh-102302 Micro-optimize `inspect.Parameter.__hash__` (python#102303) pythongh-102179: Fix `os.dup2` error reporting for negative fds (python#102180) pythongh-101892: Fix `SystemError` when a callable iterator call exhausts the iterator (python#101896) ...
test_typing
highlighted by pyflakes #102444