gh-102444: Fix minor bugs in `test_typing` highlighted by pyflakes by AlexWaygood · Pull Request #102445 · python/cpython · GitHub
Skip to content

gh-102444: Fix minor bugs in test_typing highlighted by pyflakes#102445

Merged
AlexWaygood merged 1 commit intopython:mainfrom
AlexWaygood:pyflakes-typing-tests
Mar 5, 2023
Merged

gh-102444: Fix minor bugs in test_typing highlighted by pyflakes#102445
AlexWaygood merged 1 commit intopython:mainfrom
AlexWaygood:pyflakes-typing-tests

Conversation

@AlexWaygood
Copy link
Copy Markdown
Member

@AlexWaygood AlexWaygood commented Mar 5, 2023

Comment thread Lib/test/test_typing.py
Comment on lines -7080 to -7089
Copy link
Copy Markdown
Member Author

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:

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]}
)

Comment thread Lib/test/test_typing.py

def test_bad_var_substitution(self):
T = TypeVar('T')
P = ParamSpec("P")
Copy link
Copy Markdown
Member Author

@AlexWaygood AlexWaygood Mar 5, 2023

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:

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]

Comment thread Lib/test/test_typing.py
self.assertEqual(B.__args__, ((int, str,), Tuple[bytes, float]))

def test_var_substitution(self):
T = TypeVar("T")
Copy link
Copy Markdown
Member Author

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:

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])

Comment thread Lib/test/test_typing.py
# Definitions needed for features introduced in Python 3.6

from test import ann_module, ann_module2, ann_module3, ann_module5, ann_module6
import asyncio
Copy link
Copy Markdown
Contributor

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 ;)

@AlexWaygood AlexWaygood added needs backport to 3.10 only security fixes needs backport to 3.11 only security fixes labels Mar 5, 2023
Comment thread Lib/test/test_typing.py
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]))
Copy link
Copy Markdown
Member Author

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.

@AlexWaygood AlexWaygood requested a review from sobolevn March 5, 2023 18:33
Copy link
Copy Markdown
Member

@sobolevn sobolevn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@AlexWaygood AlexWaygood merged commit 96e1022 into python:main Mar 5, 2023
@miss-islington
Copy link
Copy Markdown
Contributor

Thanks @AlexWaygood for the PR 🌮🎉.. I'm working now to backport this PR to: 3.10, 3.11.
🐍🍒⛏🤖

@AlexWaygood AlexWaygood deleted the pyflakes-typing-tests branch March 5, 2023 21:37
@miss-islington
Copy link
Copy Markdown
Contributor

Sorry, @AlexWaygood, I could not cleanly backport this to 3.10 due to a conflict.
Please backport using cherry_picker on command line.
cherry_picker 96e10229292145012bc462a6ab3ce1626c8acf71 3.10

@bedevere-bot
Copy link
Copy Markdown

GH-102451 is a backport of this pull request to the 3.11 branch.

@bedevere-bot bedevere-bot removed the needs backport to 3.11 only security fixes label Mar 5, 2023
@AlexWaygood
Copy link
Copy Markdown
Member Author

Thanks for the review @sobolevn!

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Mar 5, 2023
…kes (pythonGH-102445)

(cherry picked from commit 96e1022)

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
AlexWaygood added a commit to AlexWaygood/cpython that referenced this pull request Mar 5, 2023
@bedevere-bot
Copy link
Copy Markdown

GH-102452 is a backport of this pull request to the 3.10 branch.

@bedevere-bot bedevere-bot removed the needs backport to 3.10 only security fixes label Mar 5, 2023
miss-islington added a commit that referenced this pull request Mar 5, 2023
…H-102445)

(cherry picked from commit 96e1022)

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
AlexWaygood added a commit that referenced this pull request Mar 5, 2023
@bedevere-bot
Copy link
Copy Markdown

AlexWaygood added a commit to AlexWaygood/typing_extensions that referenced this pull request Mar 6, 2023
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)
JelleZijlstra pushed a commit to python/typing_extensions that referenced this pull request Mar 6, 2023
hugovk pushed a commit to hugovk/cpython that referenced this pull request Mar 6, 2023
carljm added a commit to carljm/cpython that referenced this pull request Mar 6, 2023
* 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)
  ...
carljm added a commit to carljm/cpython that referenced this pull request Mar 7, 2023
* 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)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip news tests Tests in the Lib/test dir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants