generics_syntax_declarations error

Invalid PEP 695 type parameter bound or constraint

PEP 695 introduced a new syntax for declaring type parameters in class and function definitions. The bound/constraint expression after : is restricted to specific forms; invalid forms are caught by this rule.

# BAD
class Foo[T: [str, int]]:  # E: list literal is not a valid bound
    ...

class Bar[T: ()]:  # E: constraint tuple must have two or more types
    ...

class Baz[T: (str,)]:  # E: constraint tuple must have two or more types
    ...

t1 = (bytes, str)
class Qux[T: t1]:  # E: constraint must be a literal tuple expression
    ...

class Bad[T: (3, bytes)]:  # E: 3 is not a valid type expression
    ...

How to handle it

Every rule is on by default — strict is the default, not a cage. You can dial generics_syntax_declarations 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/generics_syntax_declarations