Skip to content

Problem with dangling comma #434

@srittau

Description

@srittau

From python/typeshed#3358, CI: https://travis-ci.org/python/typeshed/jobs/597311318

Please consider the following file foo.pyi:

ExceptHookArgs = NamedTuple(
    "ExceptHookArgs",
    [
        ("exc_type", Type[BaseException]),
        ("exc_value", Optional[BaseException]),
        ("exc_traceback", Optional[TracebackType]),
        ("thread", Optional[Thread]),
    ],
)

pytype 2019.09.17 (Python 3.7.3) complains:

$ pytype-single --parse-pyi --module-name=foo -V3.6 foo.pyi 
Traceback (most recent call last):
  File "/home/srittau/Projekte/typeshed/.venv/lib/python3.7/site-packages/pytype/pyi/parser.py", line 430, in parse
    defs = parser_ext.parse(self, src)
pytype.pyi.parser.ParseError: ParseError: syntax error, unexpected ',', expecting ')'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "./.venv/bin/pytype-single", line 11, in <module>
    load_entry_point('pytype==2019.9.17', 'console_scripts', 'pytype-single')()
  File "/home/srittau/Projekte/typeshed/.venv/lib/python3.7/site-packages/pytype/main.py", line 88, in main
    return _run_pytype(options)
  File "/home/srittau/Projekte/typeshed/.venv/lib/python3.7/site-packages/pytype/main.py", line 96, in _run_pytype
    unused_ast = io.parse_pyi(options)
  File "/home/srittau/Projekte/typeshed/.venv/lib/python3.7/site-packages/pytype/io.py", line 263, in parse_pyi
    ast = loader.load_file(options.module_name, options.input)
  File "/home/srittau/Projekte/typeshed/.venv/lib/python3.7/site-packages/pytype/load_pytd.py", line 241, in load_file
    python_version=self.python_version)
  File "/home/srittau/Projekte/typeshed/.venv/lib/python3.7/site-packages/pytype/pyi/parser.py", line 1250, in parse_file
    src, name, filename)
  File "/home/srittau/Projekte/typeshed/.venv/lib/python3.7/site-packages/pytype/pyi/parser.py", line 440, in parse
    column=self._error_location[1], text=text)
pytype.pyi.parser.ParseError:   File: "foo.pyi", line 8
    ],
     ^
ParseError: syntax error, unexpected ',', expecting ')'

I can work around this for now, but black will re-insert the comma, so that will cause us problems in the future.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions