Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Proper construction of scope for exec/eval.#590

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
windelbouwman merged 5 commits intomasterfromexec
Mar 4, 2019
Merged

Conversation

@cthulahoops
Copy link
Collaborator

One case I couldn't handle is that the following is valid in CPython.

>>>>> exec("print(x)", None, {'x': 2})Traceback (most recent call last):  File <stdin>, line 0, in <module>TypeError: argument of type <class 'dict'> is required for parameter 2 (globals) (got: <class 'NoneType'>)

arg_check! needs to allow None and treat it as if the optional argument wasn't passed. I don't know what other builtins have this behaviour.

@codecov-io
Copy link

codecov-io commentedMar 3, 2019
edited
Loading

Codecov Report

Merging#590 intomaster willincrease coverage by2.14%.
The diff coverage is46.66%.

Impacted file tree graph

@@            Coverage Diff             @@##           master     #590      +/-   ##==========================================+ Coverage   41.61%   43.75%   +2.14%==========================================  Files          74       74                Lines       16762    17228     +466       Branches     4406     4671     +265     ==========================================+ Hits         6975     7538     +563+ Misses       7781     7594     -187- Partials     2006     2096      +90
Impacted FilesCoverage Δ
vm/src/builtins.rs35.21% <38.23%> (-8.63%)⬇️
vm/src/vm.rs52.72% <71.42%> (+1.02%)⬆️
vm/src/frame.rs47.16% <75%> (+0.05%)⬆️
vm/src/function.rs66.66% <0%> (-4.77%)⬇️
vm/src/pyobject.rs71.31% <0%> (+11.63%)⬆️
vm/src/obj/objfloat.rs58.26% <0%> (+12.44%)⬆️
vm/src/obj/objbytearray.rs61% <0%> (+15.18%)⬆️
... and4 more

Continue to review full report at Codecov.

Legend -Click here to learn more
Δ = absolute <relative> (impact),ø = not affected,? = missing data
Powered byCodecov. Last update5d28f9b...c4953ee. Read thecomment docs.

@adrian17
Copy link
Contributor

adrian17 commentedMar 3, 2019
edited
Loading

Looks like CPython doesn't do "automatic" dict type checking there, and just allows any type, then checks for None, then manually typechecks for dict.
https://github.com/python/cpython/blob/master/Python/bltinmodule.c#L1000

@cthulahoops
Copy link
CollaboratorAuthor

In that case I've added a macro to do the extra checking.

This leads me to run into the limitations of our definitions of scope. We consider local scope to be the nearest scope to us so top level statements execute with local and global scope being the same thing. In python though this means there is no local scope, creating one doesn't replace the current local==global scope.

This should work, but doesn't:

x=2exec("print(2)", None, {})

We'll need to sort this out to implement theglobals keyword, but I think what we have is okay for now.

@cthulahoops
Copy link
CollaboratorAuthor

Uh... the above is wrong. It looks like creating a new local scope never replaces the existing local scope. (Ie. that code still works even in a function.)

This is all wrong. :(

@cthulahoops
Copy link
CollaboratorAuthor

I was right the first time! :)

@cthulahoops
Copy link
CollaboratorAuthor

Interesting example:

def g():    seven = "seven"    def f():        d = {}        exec("y = seven", None, d)        assert d['y'] == seven    f()g()

locals:Option<&PyObjectRef>,
) ->ScopeRef{
let current_scope = vm.current_scope();
let parent =match globals{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Check here if globals is passed at all, None or an actual dictionary.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@windelbouwmanwindelbouwmanwindelbouwman left review comments

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

5 participants

@cthulahoops@codecov-io@adrian17@windelbouwman

[8]ページ先頭

©2009-2025 Movatter.jp