Skip to content

TypeError when parsing file with: from __future__ import (...) followed by __metaclass__ = type #1448

Description

@nathanielce24

libcst.parse_module() raises an internal TypeError when parsing a Python file that contains both:

from __future__ import (absolute_import, division, print_function) (parenthesized import)
__metaclass__ = type on the immediately following line

Reproduce With:

import libcst as cst
source = """\
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
"""
cst.parse_module(source)   # raises TypeError

Full Traceback:

Traceback (most recent call last):
  File "reproduce.py", line 8, in <module>
    cst.parse_module(source)
  File ".../libcst/_parser/entrypoints.py", line 65, in parse_module
    result = _parse(...)
  File ".../libcst/_parser/entrypoints.py", line 47, in _parse
    return parse(source_str)
  File "<string>", line 6, in __init__
  File ".../libcst/_nodes/base.py", line 118, in __post_init__
    self._validate()
  File ".../libcst/_nodes/statement.py", line 293, in _validate
    if has_no_gap and not value._safe_to_use_with_word_operator(...)
  File ".../libcst/_nodes/expression.py", line 2362, in _safe_to_use_with_word_operator
    return super()._safe_to_use_with_word_operator(position)
TypeError: super(type, obj): obj must be an instance or subtype of type

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions