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

Assertion error while loading simple module with an indirection inside a class #34

Closed
tristanlatr opened this issue Aug 27, 2021 · 3 comments · Fixed by #35
Closed

Assertion error while loading simple module with an indirection inside a class #34

tristanlatr opened this issue Aug 27, 2021 · 3 comments · Fixed by #35
Assignees
Labels
type: bug Something isn't working

Comments

@tristanlatr
Copy link
Contributor

Describe the bug
Assertion error while loading simple module with an import inside a class.

To Reproduce
Steps to reproduce the behavior:
Try to parse the following module with load_python_modules():

    class session:
        from twisted.conch.interfaces import ISession

Expected behavior
A new module should be returned, with an Indirection inside a class.

Actual bahaviour

I get the following error

self = <docspec_python.parser.Parser object at 0x106763f10>
parent = Module(name='test', members=[])
node = Node(classdef, [Leaf(1, 'class'), Leaf(1, 'session'), Leaf(11, ':'), Node(suite, [Leaf(4, '\n'), Leaf(5, '    '), Node...h'), Leaf(23, '.'), Leaf(1, 'interfaces')]), Leaf(1, 'import'), Leaf(1, 'ISession')]), Leaf(4, '\n')]), Leaf(6, '')])])
decorations = None

    def parse_classdef(self, parent, node, decorations):
      name = node.children[1].value
      bases = []
      metaclass = None
    
      # An arglist is available if there are at least two parameters.
      # Otherwise we have to deal with parsing a raw sequence of nodes.
      classargs = find(lambda x: x.type == syms.arglist, node.children)
      if classargs:
        metaclass, bases = self.parse_classdef_arglist(classargs)
      else:
        metaclass, bases = self.parse_classdef_rawargs(node)
    
      suite = find(lambda x: x.type == syms.suite, node.children)
      docstring = self.get_docstring_from_first_node(suite) if suite else None
      class_ = Class(
        name=name,
        location=self.location_from(node),
        docstring=docstring,
        metaclass=metaclass,
        bases=bases,
        decorations=decorations,
        members=[])
    
      for child in suite.children if suite else []:
        if isinstance(child, Node):
          member = self.parse_declaration(class_, child)
>         assert not isinstance(member, (list, Module)), member
E         AssertionError: [Indirection(name='ISession', target='twisted.conch.interfaces.ISession')]

It's really the indirection inside the class the issue, I've tried with the following, and it works as expected.

    from twisted.conch.interfaces import ISession
    class session:
        ISession=ISession
@NiklasRosenstein
Copy link
Owner

NiklasRosenstein commented Aug 27, 2021

Thanks for reporting @tristanlatr! 🤦 Not sure why I thought asserting here that people don't do imports in classes is a good idea.

@NiklasRosenstein
Copy link
Owner

Fixed in 1.1.1

@tristanlatr
Copy link
Contributor Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants