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
328967bd
Commit
328967bd
authored
Sep 11, 2015
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #909 from kmod/change_numdefaults
__new__ is supposed to become a staticmethod
parents
d5a4dd72
2f8ba019
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
0 deletions
+30
-0
src/runtime/descr.cpp
src/runtime/descr.cpp
+4
-0
src/runtime/objmodel.cpp
src/runtime/objmodel.cpp
+12
-0
test/tests/defaults_changing.py
test/tests/defaults_changing.py
+14
-0
No files found.
src/runtime/descr.cpp
View file @
328967bd
...
@@ -673,6 +673,10 @@ void BoxedWrapperObject::gcHandler(GCVisitor* v, Box* _o) {
...
@@ -673,6 +673,10 @@ void BoxedWrapperObject::gcHandler(GCVisitor* v, Box* _o) {
v
->
visit
(
&
o
->
obj
);
v
->
visit
(
&
o
->
obj
);
}
}
extern
"C"
PyObject
*
PyStaticMethod_New
(
PyObject
*
callable
)
noexcept
{
return
new
BoxedStaticmethod
(
callable
);
}
void
setupDescr
()
{
void
setupDescr
()
{
member_descriptor_cls
->
giveAttr
(
"__get__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
memberGet
,
UNKNOWN
,
3
)));
member_descriptor_cls
->
giveAttr
(
"__get__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
memberGet
,
UNKNOWN
,
3
)));
member_descriptor_cls
->
freeze
();
member_descriptor_cls
->
freeze
();
...
...
src/runtime/objmodel.cpp
View file @
328967bd
...
@@ -5426,6 +5426,18 @@ Box* _typeNew(BoxedClass* metatype, BoxedString* name, BoxedTuple* bases, BoxedD
...
@@ -5426,6 +5426,18 @@ Box* _typeNew(BoxedClass* metatype, BoxedString* name, BoxedTuple* bases, BoxedD
}
}
basic_size
=
cur_offset
;
basic_size
=
cur_offset
;
// from cpython:
/* Special-case __new__: if it's a plain function,
make it a static function */
Box
*
tmp
=
PyDict_GetItemString
(
attr_dict
,
"__new__"
);
if
(
tmp
!=
NULL
&&
PyFunction_Check
(
tmp
))
{
tmp
=
PyStaticMethod_New
(
tmp
);
if
(
tmp
==
NULL
)
throwCAPIException
();
PyDict_SetItemString
(
attr_dict
,
"__new__"
,
tmp
);
Py_DECREF
(
tmp
);
}
size_t
total_slots
=
final_slot_names
.
size
()
size_t
total_slots
=
final_slot_names
.
size
()
+
(
base
->
tp_flags
&
Py_TPFLAGS_HEAPTYPE
?
static_cast
<
BoxedHeapClass
*>
(
base
)
->
nslots
()
:
0
);
+
(
base
->
tp_flags
&
Py_TPFLAGS_HEAPTYPE
?
static_cast
<
BoxedHeapClass
*>
(
base
)
->
nslots
()
:
0
);
BoxedHeapClass
*
made
=
BoxedHeapClass
::
create
(
metatype
,
base
,
NULL
,
attrs_offset
,
weaklist_offset
,
basic_size
,
true
,
BoxedHeapClass
*
made
=
BoxedHeapClass
::
create
(
metatype
,
base
,
NULL
,
attrs_offset
,
weaklist_offset
,
basic_size
,
true
,
...
...
test/tests/defaults_changing.py
View file @
328967bd
...
@@ -57,3 +57,17 @@ class MyTuple(tuple):
...
@@ -57,3 +57,17 @@ class MyTuple(tuple):
f
.
func_defaults
=
MyTuple
((
1
,
2
))
f
.
func_defaults
=
MyTuple
((
1
,
2
))
print
type
(
f
.
__defaults__
)
print
type
(
f
.
__defaults__
)
f
()
f
()
class
C
(
object
):
def
__new__
(
cls
,
arg
):
print
arg
return
object
.
__new__
(
cls
)
def
foo
(
self
,
arg
):
print
arg
print
type
(
C
.
__new__
),
type
(
C
.
__dict__
[
'__new__'
])
C
.
__new__
.
__defaults__
=
(
1
,)
print
type
(
C
())
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