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
31aa93b1
Commit
31aa93b1
authored
May 18, 2015
by
Marius Wachtler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add func.__globals__/func.func_globals
parent
d217f1bc
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
0 deletions
+21
-0
src/runtime/types.cpp
src/runtime/types.cpp
+13
-0
test/tests/functions.py
test/tests/functions.py
+8
-0
No files found.
src/runtime/types.cpp
View file @
31aa93b1
...
...
@@ -848,6 +848,17 @@ static Box* functionDefaults(Box* self, void*) {
return
BoxedTuple
::
create
(
func
->
ndefaults
,
&
func
->
defaults
->
elts
[
0
]);
}
static
Box
*
functionGlobals
(
Box
*
self
,
void
*
)
{
assert
(
self
->
cls
==
function_cls
);
BoxedFunction
*
func
=
static_cast
<
BoxedFunction
*>
(
self
);
if
(
func
->
globals
)
{
assert
(
!
func
->
f
->
source
||
!
func
->
f
->
source
->
scoping
->
areGlobalsFromModule
());
return
func
->
globals
;
}
assert
(
func
->
f
->
source
);
return
getattr
(
func
->
f
->
source
->
parent_module
,
"__dict__"
);
}
static
void
functionSetDefaults
(
Box
*
b
,
Box
*
v
,
void
*
)
{
RELEASE_ASSERT
(
v
,
"can't delete __defaults__"
);
...
...
@@ -2430,6 +2441,7 @@ void setupRuntime() {
offsetof
(
BoxedFunction
,
modname
),
false
));
function_cls
->
giveAttr
(
"__doc__"
,
new
BoxedMemberDescriptor
(
BoxedMemberDescriptor
::
OBJECT
,
offsetof
(
BoxedFunction
,
doc
),
false
));
function_cls
->
giveAttr
(
"__globals__"
,
new
(
pyston_getset_cls
)
BoxedGetsetDescriptor
(
functionGlobals
,
NULL
,
NULL
));
function_cls
->
giveAttr
(
"__get__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
functionGet
,
UNKNOWN
,
3
)));
function_cls
->
giveAttr
(
"__call__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
functionCall
,
UNKNOWN
,
1
,
0
,
true
,
true
)));
...
...
@@ -2440,6 +2452,7 @@ void setupRuntime() {
function_cls
->
giveAttr
(
"func_defaults"
,
new
(
pyston_getset_cls
)
BoxedGetsetDescriptor
(
functionDefaults
,
functionSetDefaults
,
NULL
));
function_cls
->
giveAttr
(
"__defaults__"
,
function_cls
->
getattr
(
"func_defaults"
));
function_cls
->
giveAttr
(
"func_globals"
,
function_cls
->
getattr
(
"__globals__"
));
function_cls
->
freeze
();
builtin_function_or_method_cls
->
giveAttr
(
...
...
test/tests/functions.py
View file @
31aa93b1
...
...
@@ -40,3 +40,11 @@ except TypeError as e:
def
func_without_defaults
():
pass
print
repr
(
func_without_defaults
.
__defaults__
)
print
func_without_defaults
.
func_globals
==
globals
()
import
os
print
os
.
renames
.
__globals__
==
os
.
__dict__
print
os
.
renames
.
__globals__
==
globals
()
d
=
{}
exec
"def foo(): pass"
in
d
print
d
[
"foo"
].
func_globals
==
d
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