Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
Pyston
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
Boxiang Sun
Pyston
Commits
daaac1bd
Commit
daaac1bd
authored
Jan 11, 2016
by
Marius Wachtler
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1044 from undingen/minor_compat2
support type(name, bases, dict) where dict has non str keys
parents
9216f615
3267a579
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
6 deletions
+22
-6
src/runtime/objmodel.cpp
src/runtime/objmodel.cpp
+16
-6
test/tests/metaclasses.py
test/tests/metaclasses.py
+6
-0
No files found.
src/runtime/objmodel.cpp
View file @
daaac1bd
...
...
@@ -5977,13 +5977,23 @@ Box* _typeNew(BoxedClass* metatype, BoxedString* name, BoxedTuple* bases, BoxedD
made
->
setattr
(
dict_str
,
dict_descr
,
NULL
);
}
bool
are_all_dict_keys_strs
=
true
;
for
(
const
auto
&
p
:
*
attr_dict
)
{
auto
k
=
coerceUnicodeToStr
<
CXX
>
(
p
.
first
);
RELEASE_ASSERT
(
k
->
cls
==
str_cls
,
"%s"
,
k
->
cls
->
tp_name
);
BoxedString
*
s
=
static_cast
<
BoxedString
*>
(
k
);
internStringMortalInplace
(
s
);
made
->
setattr
(
s
,
p
.
second
,
NULL
);
if
(
p
.
first
->
cls
!=
str_cls
)
{
are_all_dict_keys_strs
=
false
;
break
;
}
}
if
(
are_all_dict_keys_strs
)
{
for
(
const
auto
&
p
:
*
attr_dict
)
{
BoxedString
*
s
=
static_cast
<
BoxedString
*>
(
p
.
first
);
internStringMortalInplace
(
s
);
made
->
setattr
(
s
,
p
.
second
,
NULL
);
}
}
else
{
Box
*
copy
=
PyDict_Copy
(
attr_dict
);
RELEASE_ASSERT
(
copy
,
""
);
made
->
setDictBacked
(
copy
);
}
static
BoxedString
*
module_str
=
internStringImmortal
(
"__module__"
);
...
...
test/tests/metaclasses.py
View file @
daaac1bd
...
...
@@ -57,3 +57,9 @@ print D.__base__
print
type
(
"test"
,
(),
{})
print
type
(
"test"
,
(),
{
"__module__"
:
"fake"
})
# test non str attr keys
t
=
type
(
"test"
,
(),
{
u"test"
:
2
,
1000L
:
3
,
1.0
:
4
})
print
t
.
__dict__
[
u"test"
],
t
.
test
print
t
.
__dict__
[
1000L
]
print
t
.
__dict__
[
1.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