Skip to content

typing.NoDefault is not tested to be final #149410

@sobolevn

Description

@sobolevn

Currently NoDefaultTests cover many major use-cases:

cpython/Lib/test/test_typing.py

Lines 11096 to 11132 in 426f99c

class NoDefaultTests(BaseTestCase):
def test_pickling(self):
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
s = pickle.dumps(NoDefault, proto)
loaded = pickle.loads(s)
self.assertIs(NoDefault, loaded)
def test_constructor(self):
self.assertIs(NoDefault, type(NoDefault)())
with self.assertRaises(TypeError):
type(NoDefault)(1)
def test_repr(self):
self.assertEqual(repr(NoDefault), 'typing.NoDefault')
@requires_docstrings
def test_doc(self):
self.assertIsInstance(NoDefault.__doc__, str)
def test_class(self):
self.assertIs(NoDefault.__class__, type(NoDefault))
def test_no_call(self):
with self.assertRaises(TypeError):
NoDefault()
def test_no_attributes(self):
with self.assertRaises(AttributeError):
NoDefault.foo = 3
with self.assertRaises(AttributeError):
NoDefault.foo
# TypeError is consistent with the behavior of NoneType
with self.assertRaises(TypeError):
type(NoDefault).foo = 3
with self.assertRaises(AttributeError):
type(NoDefault).foo

However, they never test that NoDefault type is final, since it does not have Py_TPFLAGS_BASETYPE flag set.

I will send a PR.

Linked PRs

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions