GithubHelp home page GithubHelp logo

safescope's People

Contributors

havakv avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

safescope's Issues

@assert_local_vars does not handle recursion

  • safescope version: 0.1.5

Description

@assert_local_vars gives an error when run with recursion.

What I Did

@assert_local_vars
def foo(x):
    if x == 0:
        return 0
    return x + foo(x-1)

---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-49-a28fcc2d95da> in <module>()
----> 1 @assert_local_vars
      2 def foo(x):
      3     if x == 0:
      4         return 0
      5     return x + foo(x-1)

~/packages/safescope/safescope/safescope.py in assert_local_vars(func)
      9     variables from enclosing scopes.
     10     '''
---> 11     var_names = get_non_local_var_names(func)
     12     if len(var_names) > 0:
     13         raise ValueError('Variables: ' + '[' + ', '.join(var_names) + '] ' +

~/packages/safescope/safescope/safescope.py in get_non_local_var_names(func)
     21     obj_names = []
     22     obj_names += non_local_callable_class_objects(func)
---> 23     obj_names += non_local_non_callable_variables(func)
     24     return obj_names
     25 

~/packages/safescope/safescope/safescope.py in non_local_non_callable_variables(func)
     65                      if len(re.findall(r'[^\.]' + name + r'[^a-zA-z0-9_]', source)) > 0]
     66 
---> 67     return [name for name in non_callables if not _name_is_module(name, func.__globals__)]

~/packages/safescope/safescope/safescope.py in <listcomp>(.0)
     65                      if len(re.findall(r'[^\.]' + name + r'[^a-zA-z0-9_]', source)) > 0]
     66 
---> 67     return [name for name in non_callables if not _name_is_module(name, func.__globals__)]

~/packages/safescope/safescope/safescope.py in _name_is_module(name, globals)
     52 def _name_is_module(name, globals):
     53     '''If name is a package in global scope.'''
---> 54     return eval(name, globals).__class__.__name__ == 'module'
     55 
     56 def non_local_non_callable_variables(func):

<string> in <module>()

NameError: name 'foo' is not defined

Proposed design change

Consider one object safescope that can be used as the wrapper @safescope, as the context manager with safescope, and has the side_scope.add method safescope.add.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.