FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[3.13] gh-118895: Call PyType_Ready() on typing.NoDefault (GH-118897) by miss-islington · Pull Request #118914 · python/cpython · GitHub

/ cpython Public
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .c  (1) .h  (1) .py  (1) .rst  (1) All 4 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
1 change: 1 addition & 0 deletions Include/internal/pycore_typevarobject.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ extern int _Py_initialize_generic(PyInterpreterState *);
extern void _Py_clear_generic_types(PyInterpreterState *);

extern PyTypeObject _PyTypeAlias_Type;
extern PyTypeObject _PyNoDefault_Type;
extern PyObject _Py_NoDefaultStruct;

#ifdef __cplusplus
Expand Down
23 changes: 21 additions & 2 deletions Lib/test/test_typing.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
import weakref
import types

from test.support import captured_stderr, cpython_only, infinite_recursion
from test.support import captured_stderr, cpython_only, infinite_recursion, requires_docstrings
from test.typinganndata import ann_module695, mod_generics_cache, _typed_dict_helper


Expand Down Expand Up @@ -10247,15 +10247,34 @@ def test_pickling(self):
def test_constructor(self):
self.assertIs(NoDefault, type(NoDefault)())
with self.assertRaises(TypeError):
NoDefault(1)
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


class AllTests(BaseTestCase):
"""Tests for __all__."""
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Setting attributes on :data:`typing.NoDefault` now raises
:exc:`AttributeError` instead of :exc:`TypeError`.
3 changes: 3 additions & 0 deletions Modules/_typingmodule.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ _typing_exec(PyObject *m)
if (PyModule_AddObjectRef(m, "TypeAliasType", (PyObject *)&_PyTypeAlias_Type) < 0) {
return -1;
}
if (PyType_Ready(&_PyNoDefault_Type) < 0) {
return -1;
}
if (PyModule_AddObjectRef(m, "NoDefault", (PyObject *)&_Py_NoDefaultStruct) < 0) {
return -1;
}
Expand Down

Back | FazBrowse Home | New Git URL