BSK-E0047
error
Invalid type expression in annotation
PEP 484 requires that annotations contain valid type expressions. Only certain expression forms are valid as types:
- Names (int, str, MyClass) - Subscripts (listint, dictstr, int) - Binary-or unions (int | str) - String literals (forward references) - None - ... (Ellipsis, in Callable signatures)
The following are invalid and should be flagged:
- List literals: int, str - Dict literals: {} - Tuple literals: (int, str) - List comprehensions: int for i in range(1) - Lambda expressions (called or uncalled) - Conditional expressions: int if cond else str - Boolean binary operators: int or str, int and str - F-string literals: f"int" - Explicit function calls like eval(...) - Negative numeric literals (positive are caught by E0024) - Names that refer to module objects (import types → types is a module, not a type) - Names that refer to unannotated literal variables (var1 = 3 → var1 is int, not a type)
def f(x: [int, str]): ... # E — list literal not a type
def g(x: int if True else str): ... # E — conditional not a type
y: {} = {} # E — dict literal not a type
How to handle it
Every rule is on by default — strict is the default, not a cage. You can dial
BSK-E0047 down per-file or per-path from your editor or
pyproject.toml, or fix the code
so it type-checks. See the Type System rules and
the complete diagnostic reference.
Canonical URL: https://www.basilisk-python.dev/errors/BSK-E0047