-
Notifications
You must be signed in to change notification settings - Fork 48
Closed
python/mypy
#18725Labels
bugcrashFailing compile-time asserts, unhandled exceptions, or generated C code that's blowing up.Failing compile-time asserts, unhandled exceptions, or generated C code that's blowing up.priority-0-high
Description
Recreating python/mypy#17794 here
Likely a duplicate of the same issue encountered in python/mypy#17321, but posting because that issue was closed.
Bug Report
Mypyc seems to encounter an error when handling Literal[<anything>]
To Reproduce
base_io.py
from __future__ import annotations
from enum import Enum
from typing import Literal, TypeAlias
class StructFormat(str, Enum):
"""All possible write/read struct types.
.. seealso:
:module:`struct` module documentation.
"""
BOOL = "?"
CHAR = "c"
BYTE = "b"
UBYTE = "B"
SHORT = "h"
USHORT = "H"
INT = "i"
UINT = "I"
LONG = "l"
ULONG = "L"
FLOAT = "f"
DOUBLE = "d"
HALFFLOAT = "e"
LONGLONG = "q"
ULONGLONG = "Q"
INT_FORMATS_TYPE: TypeAlias = Literal[
StructFormat.BYTE,
StructFormat.UBYTE,
StructFormat.SHORT,
StructFormat.USHORT,
StructFormat.INT,
StructFormat.UINT,
StructFormat.LONG,
StructFormat.ULONG,
StructFormat.LONGLONG,
StructFormat.ULONGLONG,
]
FLOAT_FORMATS_TYPE: TypeAlias = Literal[
StructFormat.FLOAT,
StructFormat.DOUBLE,
StructFormat.HALFFLOAT,
]
mypyc base_io.py
Expected Behavior
No issues
Actual Behavior
Traceback (most recent call last):
File "/home/<my username>/Desktop/build/setup.py", line 5, in <module>
ext_modules=mypycify(['base_io.py'], opt_level="3", debug_level="1"),
File "/home/<my username>/Desktop/Github-Clones/mypy-master/mypyc/build.py", line 525, in mypycify
groups, group_cfilenames = mypyc_build(
File "/home/<my username>/Desktop/Github-Clones/mypy-master/mypyc/build.py", line 435, in mypyc_build
group_cfiles, ops_text = generate_c(
File "/home/<my username>/Desktop/Github-Clones/mypy-master/mypyc/build.py", line 243, in generate_c
modules, ctext = emitmodule.compile_modules_to_c(
File "/home/<my username>/Desktop/Github-Clones/mypy-master/mypyc/codegen/emitmodule.py", line 429, in compile_modules_to_c
modules = compile_modules_to_ir(result, mapper, compiler_options, errors)
File "/home/<my username>/Desktop/Github-Clones/mypy-master/mypyc/codegen/emitmodule.py", line 273, in compile_modules_to_ir
scc_ir = compile_scc_to_ir(trees, result, mapper, compiler_options, errors)
File "/home/<my username>/Desktop/Github-Clones/mypy-master/mypyc/codegen/emitmodule.py", line 228, in compile_scc_to_ir
modules = build_ir(scc, result.graph, result.types, mapper, compiler_options, errors)
File "/usr/lib/python3.12/contextlib.py", line 81, in inner
return func(*args, **kwds)
File "/home/<my username>/Desktop/Github-Clones/mypy-master/mypyc/irbuild/main.py", line 95, in build_ir
transform_mypy_file(builder, module)
File "/home/<my username>/Desktop/Github-Clones/mypy-master/mypyc/irbuild/main.py", line 141, in transform_mypy_file
builder.accept(node)
File "/home/<my username>/Desktop/Github-Clones/mypy-master/mypyc/irbuild/builder.py", line 272, in accept
node.accept(self.visitor)
File "/home/<my username>/Desktop/Github-Clones/mypy-master/mypy/nodes.py", line 1351, in accept
return visitor.visit_assignment_stmt(self)
File "/home/<my username>/Desktop/Github-Clones/mypy-master/mypyc/irbuild/visitor.py", line 202, in visit_assignment_stmt
transform_assignment_stmt(self.builder, stmt)
File "/home/<my username>/Desktop/Github-Clones/mypy-master/mypyc/irbuild/statement.py", line 197, in transform_assignment_stmt
rvalue_reg = builder.accept(stmt.rvalue)
File "/home/<my username>/Desktop/Github-Clones/mypy-master/mypyc/irbuild/builder.py", line 258, in accept
res = node.accept(self.visitor)
File "/home/<my username>/Desktop/Github-Clones/mypy-master/mypy/nodes.py", line 2028, in accept
return visitor.visit_index_expr(self)
File "/home/<my username>/Desktop/Github-Clones/mypy-master/mypyc/irbuild/visitor.py", line 278, in visit_index_expr
return transform_index_expr(self.builder, expr)
File "/home/<my username>/Desktop/Github-Clones/mypy-master/mypyc/irbuild/expression.py", line 575, in transform_index_expr
index_reg = builder.accept(expr.index, can_borrow=is_list)
File "/home/<my username>/Desktop/Github-Clones/mypy-master/mypyc/irbuild/builder.py", line 258, in accept
res = node.accept(self.visitor)
File "/home/<my username>/Desktop/Github-Clones/mypy-master/mypy/nodes.py", line 2334, in accept
return visitor.visit_tuple_expr(self)
File "/home/<my username>/Desktop/Github-Clones/mypy-master/mypyc/irbuild/visitor.py", line 308, in visit_tuple_expr
return transform_tuple_expr(self.builder, expr)
File "/home/<my username>/Desktop/Github-Clones/mypy-master/mypyc/irbuild/expression.py", line 948, in transform_tuple_expr
reg = builder.accept(item_expr)
File "/home/<my username>/Desktop/Github-Clones/mypy-master/mypyc/irbuild/builder.py", line 258, in accept
res = node.accept(self.visitor)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/<my username>/Desktop/Github-Clones/mypy-master/mypy/nodes.py", line 1893, in accept
return visitor.visit_member_expr(self)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/<my username>/Desktop/Github-Clones/mypy-master/mypyc/irbuild/visitor.py", line 263, in visit_member_expr
return transform_member_expr(self.builder, expr)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/<my username>/Desktop/Github-Clones/mypy-master/mypyc/irbuild/expression.py", line 204, in transform_member_expr
final_var, fullname, final_var.name, native, builder.types[expr], expr.line
~~~~~~~~~~~~~^^^^^^
base_io.py:32: KeyError: <mypy.nodes.MemberExpr object at 0x775591a0b920>
Your Environment
- Mypy version used:
mypy 1.12.0+dev.7f3d7f8f10938618bcf8648d92f6a3da0a01117f (compiled: no)
- Mypy command-line flags: None
- Mypy configuration options from
mypy.ini
(and other config files): None - Python version used:
Python 3.12.3 (main, Sep 11 2024, 14:17:37) [GCC 13.2.0] on linux
Metadata
Metadata
Assignees
Labels
bugcrashFailing compile-time asserts, unhandled exceptions, or generated C code that's blowing up.Failing compile-time asserts, unhandled exceptions, or generated C code that's blowing up.priority-0-high