Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError in _filter_ast_node #37

Closed
alexlouden opened this issue Oct 23, 2017 · 1 comment
Closed

AttributeError in _filter_ast_node #37

alexlouden opened this issue Oct 23, 2017 · 1 comment

Comments

@alexlouden
Copy link

I was testing the following import:
import ipynb.fs.defs.utils.testfoo

and got the following exception:

... ipynb/fs/defs/__init__.py in <listcomp>(.0)
     39         if isinstance(node, ast.Assign):
---> 40             return all([t.id.isupper() for t in node.targets])

AttributeError: 'Subscript' object has no attribute 'id'

So I modified the _filter_ast_node to include a couple of try/excepts to see where it was failing:

        if isinstance(node, ast.Assign):
            try:
                return all([t.id.isupper() for t in node.targets])
            except AttributeError:
                print(ast.dump(node))
                for t in node.targets:
                    try:
                        t.id
                    except AttributeError:
                        print(ast.dump(t))
                raise

ast.dump(node):

Assign(targets=[Subscript(value=Name(id='df', ctx=Load()), slice=Index(value=Str(s='test')), ctx=Store())], value=Str(s='foo'))

ast.dump(t):

Subscript(value=Name(id='df', ctx=Load()), slice=Index(value=Str(s='test')), ctx=Store())

Looks like it's occurring on the following line of my notebook:

df['test'] = 'foo'

One possible solution:

    def _filter_ast_node(self, node):
        for an in ALLOWED_NODES:
            if isinstance(node, an):
                return True

        if isinstance(node, ast.Assign):
            return all(self._id_is_upper(t) for t in node.targets)

        return False

    @staticmethod
    def _id_is_upper(t):
        try:
            return t.id.isupper()
        except AttributeError:
            return False
@alexlouden
Copy link
Author

Never mind, looks like f663f8f should fix this

tonyfast added a commit to deathbeds/ipynb that referenced this issue Jan 2, 2020
…python#38)

* Simplify the way we handle exceptions
* Add tests for capture_output and partial
* Add Lazy to the top level API
* Include a notebook parameterization module (ipython#37)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant