TypeError when parsing file with: from __future__ import (...) followed by __metaclass__ = type
- Dominant language
- Python
- Stars
- 1.9k
- Forks
- 229
- PR merge metrics
- No merged PRs in 30d
Description
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
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 "", 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
```
Contributor guide
Assessment
This issue has not been assessed yet.