Skip to content

PY-TYPE0004 · prohibited_annotation

Count prohibited universal types in every Python annotation position.

This is a deterministic rule for python. Read its implementation.

Inspect function parameters and returns, annotated variables and attributes, PEP 695 and explicit TypeAlias values, generic bases, type-parameter bounds and defaults, nested generic arguments, string annotations, and type comments. Resolve direct and aliased imports from typing, typing_extensions, and builtins. Bare object resolves to the built-in unless a lexical binding conservatively shadows it. Each prohibited occurrence contributes one to the result. Configure any subset of Any and object through prohibited.

Each finding identifies the resolved universal type and the annotation source line. Nested occurrences remain separate evidence because each can require a different replacement. The value is the number of prohibited universal types across every annotation position.

Unresolved names, wildcard imports, and names with another binding in the same lexical scope are not reported. Values outside annotation positions are ignored. External stub boundaries can disable one prohibition or the complete rule when their published contract requires it.

Bad

`from typing import Any as Dynamic`, `payload: list[Dynamic]`, `value: object`, and
`class Adapter(Protocol[Any])` contain prohibited universal types.
Good

payload: Mapping[str, JsonValue] describes a capability. After object = DomainRoot, value: object is conservatively treated as the project type rather than the built-in.