Skip to content

Lack of error message when a variable is annotated with Final without explicit type. #990

@yilei

Description

@yilei

Reproducible steps:

$ git clone https://github.com/psf/black
$ cd black
$ git checkout a552f7096a9f6e016c9bb1df1e0a77a17caeec1c
$ pip install -e .[d]
$ cd src/
$ mypyc blib2to3/

It fails with the following error message:

Traceback (most recent call last):
  File "mypyc/irbuild/builder.py", line 247, in accept
  File "mypy/nodes.py", line 1793, in accept
  File "mypyc/irbuild/visitor.py", line 251, in visit_name_expr
  File "mypyc/irbuild/expression.py", line 130, in transform_name_expr
  File "mypyc/irbuild/builder.py", line 992, in emit_load_final
  File "mypyc/irbuild/builder.py", line 540, in load_final_static
blib2to3/pgen2/tokenize.py:559: AssertionError:

The line in question from Black is https://github.com/psf/black/blob/a552f7096a9f6e016c9bb1df1e0a77a17caeec1c/src/blib2to3/pgen2/tokenize.py#L559

numchars was declared earlier as:

numchars: Final = "0123456789"

Changing it to

numchars: Final[str] = "0123456789"

would make mypyc succeed.

But the original error message is hard to understand.

This is a new issue since mypy 1.0.0, Black is currently using 0.991.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugcrashFailing compile-time asserts, unhandled exceptions, or generated C code that's blowing up.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions