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
01fc6cd0
Commit
01fc6cd0
authored
Aug 17, 2011
by
Benjamin Peterson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make __doc__ mutable on heaptypes (closes #12773)
parent
d9f23d20
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
1 deletion
+25
-1
Lib/test/test_descr.py
Lib/test/test_descr.py
+13
-0
Misc/NEWS
Misc/NEWS
+2
-0
Objects/typeobject.c
Objects/typeobject.c
+10
-1
No files found.
Lib/test/test_descr.py
View file @
01fc6cd0
...
...
@@ -4261,6 +4261,19 @@ order (MRO) for bases """
m
=
str
(
cm
.
exception
)
self
.
assertEqual
(
"'foo' in __slots__ conflicts with class variable"
,
m
)
def
test_set_doc
(
self
):
class
X
:
"elephant"
X
.
__doc__
=
"banana"
self
.
assertEqual
(
X
.
__doc__
,
"banana"
)
with
self
.
assertRaises
(
TypeError
)
as
cm
:
type
(
list
).
__dict__
[
"__doc__"
].
__set__
(
list
,
"blah"
)
self
.
assertIn
(
"can't set list.__doc__"
,
str
(
cm
.
exception
))
with
self
.
assertRaises
(
TypeError
)
as
cm
:
type
(
X
).
__dict__
[
"__doc__"
].
__delete__
(
X
)
self
.
assertIn
(
"can't delete X.__doc__"
,
str
(
cm
.
exception
))
self
.
assertEqual
(
X
.
__doc__
,
"banana"
)
class
DictProxyTests
(
unittest
.
TestCase
):
def
setUp
(
self
):
class
C
(
object
):
...
...
Misc/NEWS
View file @
01fc6cd0
...
...
@@ -10,6 +10,8 @@ What's New in Python 3.3 Alpha 1?
Core and Builtins
-----------------
- Issue #12773: Make __doc__ mutable on user-defined classes.
- Issue #12766: Raise an ValueError when creating a class with a class variable
that conflicts with a name in __slots__.
...
...
Objects/typeobject.c
View file @
01fc6cd0
...
...
@@ -588,6 +588,15 @@ type_get_doc(PyTypeObject *type, void *context)
return
result
;
}
static
int
type_set_doc
(
PyTypeObject
*
type
,
PyObject
*
value
,
void
*
context
)
{
if
(
!
check_set_special_type_attr
(
type
,
value
,
"__doc__"
))
return
-
1
;
PyType_Modified
(
type
);
return
PyDict_SetItemString
(
type
->
tp_dict
,
"__doc__"
,
value
);
}
static
PyObject
*
type___instancecheck__
(
PyObject
*
type
,
PyObject
*
inst
)
{
...
...
@@ -623,7 +632,7 @@ static PyGetSetDef type_getsets[] = {
{
"__abstractmethods__"
,
(
getter
)
type_abstractmethods
,
(
setter
)
type_set_abstractmethods
,
NULL
},
{
"__dict__"
,
(
getter
)
type_dict
,
NULL
,
NULL
},
{
"__doc__"
,
(
getter
)
type_get_doc
,
NULL
,
NULL
},
{
"__doc__"
,
(
getter
)
type_get_doc
,
(
setter
)
type_set_doc
,
NULL
},
{
0
}
};
...
...
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