Skip to content

Commit

Permalink
Address review
Browse files Browse the repository at this point in the history
  • Loading branch information
sobolevn committed Sep 26, 2024
1 parent 87b91c0 commit 2105925
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Lib/test/test_type_aliases.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def test_generic(self):
self.assertEqual(TA.__value__, list[T])
self.assertEqual(TA.__type_params__, (T,))
self.assertEqual(TA.__module__, __name__)
self.assertIs(TA[int].__class__, types.GenericAlias)
self.assertIs(type(TA[int]), types.GenericAlias)

def test_not_generic(self):
TA = TypeAliasType("TA", list[int], type_params=())
Expand Down
14 changes: 11 additions & 3 deletions Objects/typevarobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -1914,7 +1914,16 @@ typealias_alloc(PyObject *name, PyObject *type_params, PyObject *compute_value,
return NULL;
}
ta->name = Py_NewRef(name);
ta->type_params = Py_IsNone(type_params) ? NULL : Py_XNewRef(type_params);
if (
type_params == NULL
|| Py_IsNone(type_params)
|| (PyTuple_Check(type_params) && PyTuple_GET_SIZE(type_params) == 0)
) {
ta->type_params = NULL;
}
else {
ta->type_params = Py_NewRef(type_params);
}
ta->compute_value = Py_XNewRef(compute_value);
ta->value = Py_XNewRef(value);
ta->module = Py_XNewRef(module);
Expand Down Expand Up @@ -1957,8 +1966,7 @@ typealias_reduce_impl(typealiasobject *self)
static PyObject *
typealias_subscript(PyObject *self, PyObject *args)
{
typealiasobject *ta = ((typealiasobject *)self);
if (ta->type_params == NULL || PyTuple_GET_SIZE(ta->type_params) == 0) {
if (((typealiasobject *)self)->type_params == NULL) {
PyErr_SetString(PyExc_TypeError,
"Only generic type aliases are subscriptable");
return NULL;
Expand Down

0 comments on commit 2105925

Please sign in to comment.