| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10377,6 +10377,17 @@ def test_paramspec_in_nested_generics(self): | |||
| 10377 | 10377 | self.assertEqual(G2[[int, str], float], list[C]) | |
| 10378 | 10378 | self.assertEqual(G3[[int, str], float], list[C] | int) | |
| 10379 | 10379 | ||
| 10380 | + def test_paramspec_bound(self): | ||
| 10381 | + P = ParamSpec('P', bound=[int, str]) | ||
| 10382 | + self.assertEqual(P.__bound__, [int, str]) | ||
| 10383 | + P2 = ParamSpec('P2', bound=(int, str)) | ||
| 10384 | + self.assertEqual(P2.__bound__, (int, str)) | ||
| 10385 | + obj = object() | ||
| 10386 | + P3 = ParamSpec('P3', bound=obj) | ||
| 10387 | + self.assertIs(P3.__bound__, obj) | ||
| 10388 | + P4 = ParamSpec('P4') | ||
| 10389 | + self.assertIs(P4.__bound__, None) | ||
| 10390 | + | ||
| 10380 | 10391 | def test_paramspec_gets_copied(self): | |
| 10381 | 10392 | # bpo-46581 | |
| 10382 | 10393 | P = ParamSpec('P') | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,2 @@ | |||
| 1 | + Allow more types to be used in the ``bound`` argument to | ||
| 2 | + :class:`typing.ParamSpec`. | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1334,20 +1334,12 @@ paramspec_new_impl(PyTypeObject *type, PyObject *name, PyObject *bound, | |||
| 1334 | 1334 | PyErr_SetString(PyExc_ValueError, "Variance cannot be specified with infer_variance."); | |
| 1335 | 1335 | return NULL; | |
| 1336 | 1336 | } | |
| 1337 | - if (bound != NULL) { | ||
| 1338 | - bound = type_check(bound, "Bound must be a type."); | ||
| 1339 | - if (bound == NULL) { | ||
| 1340 | - return NULL; | ||
| 1341 | - } | ||
| 1342 | - } | ||
| 1343 | 1337 | PyObject *module = caller(); | |
| 1344 | 1338 | if (module == NULL) { | |
| 1345 | - Py_XDECREF(bound); | ||
| 1346 | 1339 | return NULL; | |
| 1347 | 1340 | } | |
| 1348 | 1341 | PyObject *ps = (PyObject *)paramspec_alloc( | |
| 1349 | 1342 | name, bound, default_value, covariant, contravariant, infer_variance, module); | |
| 1350 | - Py_XDECREF(bound); | ||
| 1351 | 1343 | Py_DECREF(module); | |
| 1352 | 1344 | return ps; | |
| 1353 | 1345 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments