8000 fix some tests · python/cpython@6ab8b1e · GitHub
[go: up one dir, main page]

Skip to content

Commit 6ab8b1e

Browse files
committed
fix some tests
1 parent d9ec56e commit 6ab8b1e

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

Lib/test/test_type_params.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,11 +218,12 @@ def method[T](self, arg: x): pass
218218

219219
def test_class_scope_interaction_02(self):
220220
code = textwrap.dedent("""\
221+
from typing import Generic
221222
class C:
222223
class Base: pass
223224
class Child[T](Base): pass
224225
225-
assert C.Child.__bases__ == (C.Base,)
226+
assert C.Child.__bases__ == (C.Base, Generic)
226227
""")
227228
exec(code, {})
228229

@@ -369,7 +370,7 @@ def get_typeparams():
369370

370371
a, b, c, d = Outer.Inner.get_typeparams()
371372
self.assertEqual(Outer.__type_variables__, (a, b))
372-
self.assertEqual(Outer.Inner.__type_variables__, (a, b, c, d))
373+
self.assertEqual(Outer.Inner.__type_variables__, (c, d))
373374

374375
self.assertEqual(Outer.__parameters__, (a, b))
375376
self.assertEqual(Outer.Inner.__parameters__, (c, d))
@@ -401,7 +402,7 @@ def inner[C, D]():
401402
inner = outer()
402403
a, b, c, d = inner()
403404
self.assertEqual(outer.__type_variables__, (a, b))
404-
self.assertEqual(inner.__type_variables__, (a, b, c, d))
405+
self.assertEqual(inner.__type_variables__, (c, d))
405406

406407
def test_typeparams_dunder_function_02(self):
407408
def func1():

Objects/typevarobject.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,18 @@ typevar_reduce_impl(typevarobject *self)
240240
return PyUnicode_FromString(self->name);
241241
}
242242

243+
static PyObject *
244+
typevar_mro_entries(PyObject *self, PyObject *args)
245+
{
246+
PyErr_SetString(PyExc_TypeError,
247+
"Cannot subclass an instance of TypeVar");
248+
return NULL;
249+
}
250+
243251
static PyMethodDef typevar_methods[] = {
244252
TYPEVAR_TYPING_SUBST_METHODDEF
245253
TYPEVAR_REDUCE_METHODDEF
254+
{"__mro_entries__", typevar_mro_entries, METH_O},
246255
{0}
247256
};
248257

@@ -697,10 +706,19 @@ paramspec_reduce_impl(paramspecobject *self)
697706
return PyUnicode_FromString(self->name);
698707
}
699708

709+
static PyObject *
710+
paramspec_mro_entries(PyObject *self, PyObject *args)
711+
{
712+
PyErr_SetString(PyExc_TypeError,
713+
"Cannot subclass an instance of ParamSpec");
714+
return NULL;
715+
}
716+
700717
static PyMethodDef paramspec_methods[] = {
701718
PARAMSPEC_TYPING_SUBST_METHODDEF
702719
PARAMSPEC_TYPING_PREPARE_SUBST_METHODDEF
703720
PARAMSPEC_REDUCE_METHODDEF
721+
{"__mro_entries__", paramspec_mro_entries, METH_O},
704722
{0}
705723
};
706724

@@ -902,10 +920,19 @@ typevartuple_reduce_impl(typevartupleobject *self)
902920
return PyUnicode_FromString(self->name);
903921
}
904922

923+
static PyObject *
924+
typevartuple_mro_entries(PyObject *self, PyObject *args)
925+
{
926+
PyErr_SetString(PyExc_TypeError,
927+
"Cannot subclass an instance of TypeVarTuple");
928+
return NULL;
929+
}
930+
905931
static PyMethodDef typevartuple_methods[] = {
906932
TYPEVARTUPLE_TYPING_SUBST_METHODDEF
907933
TYPEVARTUPLE_TYPING_PREPARE_SUBST_METHODDEF
908934
TYPEVARTUPLE_REDUCE_METHODDEF
935+
{"__mro_entries__", typevartuple_mro_entries, METH_O},
909936
{0}
910937
};
911938

0 commit comments

Comments
 (0)
0