Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6df4913

Browse files
[3.13]gh-118895: Call PyType_Ready() on typing.NoDefault (GH-118897) (#118914)
(cherry picked from commit13d7cf9)Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
1 parent0becae3 commit6df4913

File tree

4 files changed

+27
-2
lines changed

4 files changed

+27
-2
lines changed

‎Include/internal/pycore_typevarobject.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ extern int _Py_initialize_generic(PyInterpreterState *);
1818
externvoid_Py_clear_generic_types(PyInterpreterState*);
1919

2020
externPyTypeObject_PyTypeAlias_Type;
21+
externPyTypeObject_PyNoDefault_Type;
2122
externPyObject_Py_NoDefaultStruct;
2223

2324
#ifdef__cplusplus

‎Lib/test/test_typing.py‎

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
importweakref
4646
importtypes
4747

48-
fromtest.supportimportcaptured_stderr,cpython_only,infinite_recursion
48+
fromtest.supportimportcaptured_stderr,cpython_only,infinite_recursion,requires_docstrings
4949
fromtest.typinganndataimportann_module695,mod_generics_cache,_typed_dict_helper
5050

5151

@@ -10247,15 +10247,34 @@ def test_pickling(self):
1024710247
deftest_constructor(self):
1024810248
self.assertIs(NoDefault,type(NoDefault)())
1024910249
withself.assertRaises(TypeError):
10250-
NoDefault(1)
10250+
type(NoDefault)(1)
1025110251

1025210252
deftest_repr(self):
1025310253
self.assertEqual(repr(NoDefault),'typing.NoDefault')
1025410254

10255+
@requires_docstrings
10256+
deftest_doc(self):
10257+
self.assertIsInstance(NoDefault.__doc__,str)
10258+
10259+
deftest_class(self):
10260+
self.assertIs(NoDefault.__class__,type(NoDefault))
10261+
1025510262
deftest_no_call(self):
1025610263
withself.assertRaises(TypeError):
1025710264
NoDefault()
1025810265

10266+
deftest_no_attributes(self):
10267+
withself.assertRaises(AttributeError):
10268+
NoDefault.foo=3
10269+
withself.assertRaises(AttributeError):
10270+
NoDefault.foo
10271+
10272+
# TypeError is consistent with the behavior of NoneType
10273+
withself.assertRaises(TypeError):
10274+
type(NoDefault).foo=3
10275+
withself.assertRaises(AttributeError):
10276+
type(NoDefault).foo
10277+
1025910278

1026010279
classAllTests(BaseTestCase):
1026110280
"""Tests for __all__."""
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Setting attributes on:data:`typing.NoDefault` now raises
2+
:exc:`AttributeError` instead of:exc:`TypeError`.

‎Modules/_typingmodule.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ _typing_exec(PyObject *m)
6363
if (PyModule_AddObjectRef(m,"TypeAliasType", (PyObject*)&_PyTypeAlias_Type)<0) {
6464
return-1;
6565
}
66+
if (PyType_Ready(&_PyNoDefault_Type)<0) {
67+
return-1;
68+
}
6669
if (PyModule_AddObjectRef(m,"NoDefault", (PyObject*)&_Py_NoDefaultStruct)<0) {
6770
return-1;
6871
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp