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.
This commit is contained in:
Serhiy Storchaka 2024-08-07 23:30:10 +03:00 committed by GitHub
parent e73e7a7abd
commit 540fcc62f5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 165 additions and 7 deletions

View file

@ -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):