diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2024-08-07 20:30:10 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-07 20:30:10 (GMT) |
commit | 540fcc62f5da982b79504221cac01bfab8b73ba1 (patch) | |
tree | 0e5b279cb9f2f358197a673ddf7a5a7959c07209 /Lib/test/test_typing.py | |
parent | e73e7a7abdc3fed252affcb1629df1b3c8fff2ef (diff) | |
download | cpython-540fcc62f5da982b79504221cac01bfab8b73ba1.zip cpython-540fcc62f5da982b79504221cac01bfab8b73ba1.tar.gz cpython-540fcc62f5da982b79504221cac01bfab8b73ba1.tar.bz2 |
gh-118814: Fix the TypeVar constructor when name is passed by keyword (GH-122664)
Fix _PyArg_UnpackKeywordsWithVararg for the case when argument for
positional-or-keyword parameter is passed by keyword.
There was only one such case in the stdlib -- the TypeVar constructor.
Diffstat (limited to 'Lib/test/test_typing.py')
-rw-r--r-- | Lib/test/test_typing.py | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py index 290b3c6..8baa415 100644 --- a/Lib/test/test_typing.py +++ b/Lib/test/test_typing.py @@ -579,6 +579,55 @@ class TypeVarTests(BaseTestCase): self.assertEqual(T.__name__, "T") self.assertEqual(T.__constraints__, ()) self.assertIs(T.__bound__, None) + self.assertIs(T.__default__, typing.NoDefault) + self.assertIs(T.__covariant__, False) + self.assertIs(T.__contravariant__, False) + self.assertIs(T.__infer_variance__, False) + + T = TypeVar(name="T", bound=type) + self.assertEqual(T.__name__, "T") + self.assertEqual(T.__constraints__, ()) + self.assertIs(T.__bound__, type) + self.assertIs(T.__default__, typing.NoDefault) + self.assertIs(T.__covariant__, False) + self.assertIs(T.__contravariant__, False) + self.assertIs(T.__infer_variance__, False) + + T = TypeVar(name="T", default=()) + self.assertEqual(T.__name__, "T") + self.assertEqual(T.__constraints__, ()) + self.assertIs(T.__bound__, None) + self.assertIs(T.__default__, ()) + self.assertIs(T.__covariant__, False) + self.assertIs(T.__contravariant__, False) + self.assertIs(T.__infer_variance__, False) + + T = TypeVar(name="T", covariant=True) + self.assertEqual(T.__name__, "T") + self.assertEqual(T.__constraints__, ()) + self.assertIs(T.__bound__, None) + self.assertIs(T.__default__, typing.NoDefault) + self.assertIs(T.__covariant__, True) + self.assertIs(T.__contravariant__, False) + self.assertIs(T.__infer_variance__, False) + + T = TypeVar(name="T", contravariant=True) + self.assertEqual(T.__name__, "T") + self.assertEqual(T.__constraints__, ()) + self.assertIs(T.__bound__, None) + self.assertIs(T.__default__, typing.NoDefault) + self.assertIs(T.__covariant__, False) + self.assertIs(T.__contravariant__, True) + self.assertIs(T.__infer_variance__, False) + + T = TypeVar(name="T", infer_variance=True) + self.assertEqual(T.__name__, "T") + self.assertEqual(T.__constraints__, ()) + self.assertIs(T.__bound__, None) + self.assertIs(T.__default__, typing.NoDefault) + self.assertIs(T.__covariant__, False) + self.assertIs(T.__contravariant__, False) + self.assertIs(T.__infer_variance__, True) class TypeParameterDefaultsTests(BaseTestCase): |