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
e50e0667
Commit
e50e0667
authored
Aug 16, 2011
by
Benjamin Peterson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
complain when a class variable shadows a name in __slots__ (closes #12766)
parent
8a898752
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
0 deletions
+17
-0
Lib/test/test_descr.py
Lib/test/test_descr.py
+8
-0
Misc/NEWS
Misc/NEWS
+3
-0
Objects/typeobject.c
Objects/typeobject.c
+6
-0
No files found.
Lib/test/test_descr.py
View file @
e50e0667
...
...
@@ -4253,6 +4253,14 @@ order (MRO) for bases """
foo
=
Foo
()
str
(
foo
)
def
test_slot_shadows_class
(
self
):
with
self
.
assertRaises
(
ValueError
)
as
cm
:
class
X
:
__slots__
=
[
"foo"
]
foo
=
None
m
=
str
(
cm
.
exception
)
self
.
assertEqual
(
"'foo' in __slots__ conflicts with class variable"
,
m
)
class
DictProxyTests
(
unittest
.
TestCase
):
def
setUp
(
self
):
class
C
(
object
):
...
...
Misc/NEWS
View file @
e50e0667
...
...
@@ -10,6 +10,9 @@ What's New in Python 3.3 Alpha 1?
Core and Builtins
-----------------
- Issue #12766: Raise an ValueError when creating a class with a class variable
that conflicts with a name in __slots__.
- Issue #12266: Fix str.capitalize() to correctly uppercase/lowercase
titlecased and cased non-letter characters.
...
...
Objects/typeobject.c
View file @
e50e0667
...
...
@@ -2094,6 +2094,12 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds)
if
(
!
tmp
)
goto
bad_slots
;
PyList_SET_ITEM
(
newslots
,
j
,
tmp
);
if
(
PyDict_GetItem
(
dict
,
tmp
))
{
PyErr_Format
(
PyExc_ValueError
,
"%R in __slots__ conflicts with class variable"
,
tmp
);
goto
bad_slots
;
}
j
++
;
}
assert
(
j
==
nslots
-
add_dict
-
add_weak
);
...
...
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