Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
547298c9
Commit
547298c9
authored
Oct 16, 2012
by
Eric Snow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Close #16160: Subclass support now works for types.SimpleNamespace. Thanks to RDM for noticing.
parent
e54c7185
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
12 deletions
+23
-12
Lib/test/test_types.py
Lib/test/test_types.py
+9
-0
Misc/NEWS
Misc/NEWS
+2
-0
Objects/namespaceobject.c
Objects/namespaceobject.c
+12
-12
No files found.
Lib/test/test_types.py
View file @
547298c9
...
...
@@ -1135,6 +1135,15 @@ class SimpleNamespaceTests(unittest.TestCase):
with
self
.
assertRaises
(
TypeError
):
ns
[
'spam'
]
def
test_subclass
(
self
):
class
Spam
(
types
.
SimpleNamespace
):
pass
spam
=
Spam
(
ham
=
8
,
eggs
=
9
)
self
.
assertIs
(
type
(
spam
),
Spam
)
self
.
assertEqual
(
vars
(
spam
),
{
'ham'
:
8
,
'eggs'
:
9
})
def
test_main
():
run_unittest
(
TypesTests
,
MappingProxyTests
,
ClassCreationTests
,
...
...
Misc/NEWS
View file @
547298c9
...
...
@@ -15,6 +15,8 @@ Core and Builtins
- Issue #14783: Improve int() docstring and switch docstrings for str(),
range(), and slice() to use multi-line signatures.
- Issue #16160: Subclass support now works for types.SimpleNamespace.
- Issue #15379: Fix passing of non-BMP characters as integers for the charmap
decoder (already working as unicode strings). Patch by Serhiy Storchaka.
...
...
Objects/namespaceobject.c
View file @
547298c9
...
...
@@ -21,19 +21,19 @@ static PyMemberDef namespace_members[] = {
static
PyObject
*
namespace_new
(
PyTypeObject
*
type
,
PyObject
*
args
,
PyObject
*
kwds
)
{
_PyNamespaceObject
*
ns
;
ns
=
PyObject_GC_New
(
_PyNamespaceObject
,
&
_PyNamespace_Type
);
if
(
ns
==
NULL
)
return
NULL
;
ns
->
ns_dict
=
PyDict_New
();
if
(
ns
->
ns_dict
==
NULL
)
{
Py_DECREF
(
ns
);
return
NULL
;
PyObject
*
self
;
assert
(
type
!=
NULL
&&
type
->
tp_alloc
!=
NULL
);
self
=
type
->
tp_alloc
(
type
,
0
);
if
(
self
!=
NULL
)
{
_PyNamespaceObject
*
ns
=
(
_PyNamespaceObject
*
)
self
;
ns
->
ns_dict
=
PyDict_New
();
if
(
ns
->
ns_dict
==
NULL
)
{
Py_DECREF
(
ns
);
return
NULL
;
}
}
PyObject_GC_Track
(
ns
);
return
(
PyObject
*
)
ns
;
return
self
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment