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

Parsing error when a class defined with metaclass keyword #192

Open
sjiang1 opened this issue Oct 3, 2019 · 1 comment
Open

Parsing error when a class defined with metaclass keyword #192

sjiang1 opened this issue Oct 3, 2019 · 1 comment

Comments

@sjiang1
Copy link

sjiang1 commented Oct 3, 2019

The file, test3.py, being parsed:

from abc import ABCMeta, abstractmethod
class Employee(metaclass=ABCMeta):
    pass

The test case:

from redbaron import RedBaron
with open("test3.py", "r") as source_code:
    red = RedBaron(source_code.read())

Error message:

Traceback (most recent call last):
  File "demo.py", line 6, in <module>
    red = RedBaron(source_code.read())
  File "../redbaron/redbaron/redbaron.py", line 36, in __init__
    self.node_list = base_nodes.NodeList.from_fst(baron.parse(source_code), parent=self, on_attribute="root")
  File "../redbaron/redbaron/base_nodes.py", line 335, in from_fst
    parent=parent, on_attribute=on_attribute)
  File "../redbaron/redbaron/base_nodes.py", line 328, in __init__
    super(NodeList, self).__init__(initlist)
  File "/usr/lib/python3.6/collections/__init__.py", line 1039, in __init__
    self.data = list(initlist)
  File "../redbaron/redbaron/base_nodes.py", line 334, in <lambda>
    return klass(map(lambda x: Node.from_fst(x, parent=parent, on_attribute=on_attribute), node_list),
  File "../redbaron/redbaron/base_nodes.py", line 537, in from_fst
    return getattr(redbaron.nodes, class_name)(node, parent=parent, on_attribute=on_attribute)
  File "../redbaron/redbaron/base_nodes.py", line 526, in __init__
    setattr(self, key, NodeList.from_fst(fst[key], parent=self, on_attribute=key))
  File "../redbaron/redbaron/base_nodes.py", line 335, in from_fst
    parent=parent, on_attribute=on_attribute)
  File "../redbaron/redbaron/base_nodes.py", line 328, in __init__
    super(NodeList, self).__init__(initlist)
  File "/usr/lib/python3.6/collections/__init__.py", line 1039, in __init__
    self.data = list(initlist)
  File "../redbaron/redbaron/base_nodes.py", line 334, in <lambda>
    return klass(map(lambda x: Node.from_fst(x, parent=parent, on_attribute=on_attribute), node_list),
  File "../redbaron/redbaron/base_nodes.py", line 536, in from_fst
    class_name = baron_type_to_redbaron_classname(node["type"])
TypeError: list indices must be integers or slices, not str
@sjiang1 sjiang1 changed the title Parsing Error when a class defined with metaclass keyword Parsing error when a class defined with metaclass keyword Oct 3, 2019
sjiang1 added a commit to sjiang1/redbaron that referenced this issue Oct 3, 2019
Parsing error when a class defined with metaclass keyword

Detailed discussion in grandfoosier/EMUresearch.
@olliemath
Copy link

olliemath commented Oct 21, 2021

Oh wow, this is old .. yup, just hit this issue

red = RedBaron("""
class Foo(metaclass=MetaFoo): 
    pass
""")

still causes a TypeError.

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

2 participants