Python Type Hints taste
# Python Type Hints taste of a typed-Python maintainer - Run a type checker (pyright or mypy) in CI on every pull request and treat new errors as build failures. Confidence: 0.95 - Start strict on new code with strict =
Works with
claude-code (compatible), claude (compatible), codex (compatible), chatgpt (compatible), gemini-cli (compatible), cursor (compatible), copilot (compatible), opencode (compatible), amp (compatible), roo (compatible), kiro (compatible), goose (compatible), junie (compatible), trae (compatible), cline (compatible), continue (compatible), antigravity (compatible), windsurf (compatible), augment (compatible), qwen-code (compatible), aider (compatible)
Content
Python Type Hints taste of a typed-Python maintainer
- Run a type checker (pyright or mypy) in CI on every pull request and treat new errors as build failures. Confidence: 0.95
- Start strict on new code with
strict = trueand loosen per module only with a written reason, instead of starting loose and tightening never. Confidence: 0.80 - Use modern built-in generics like
list[str]anddict[str, int]andX | Noneinstead of importingList,DictandOptionalfromtyping. Confidence: 0.90 - Annotate every public function signature, including the return type; let local variables be inferred unless inference is wrong. Confidence: 0.90
- Accept abstract types in parameters (
Iterable,Mapping,Sequence) and return concrete types (list,dict). Confidence: 0.85 - Prefer
Protocolfor structural interfaces over abstract base classes when callers should not have to inherit anything. Confidence: 0.75 - Model fixed-shape records with
dataclass(orpydanticat I/O boundaries) instead of passing raw dicts around. Confidence: 0.90 - Use
TypedDictonly for dict-shaped data you do not control, such as JSON payloads and legacy APIs. Confidence: 0.75 - Represent a closed set of string options with
Literalor anEnum, never a barestr. Confidence: 0.85 - Treat
Anyas a bug report: confine it to the boundary where untyped data enters and narrow it immediately. Confidence: 0.85 - Prefer
objectoverAnywhen a value is truly unknown, so the checker forces a narrowing step before use. Confidence: 0.70 - Narrow with
isinstance,matchstatements andTypeGuard/TypeIshelpers instead ofcast(). Confidence: 0.80 - Every
# type: ignoremust name the error code and carry a short comment explaining why it is safe. Confidence: 0.90 - Use
NewTypefor IDs and units (UserId,Cents) that are easy to mix up but share an underlying type. Confidence: 0.70 - Ship a
py.typedmarker in libraries and keep stubs for untyped dependencies in a pinnedtypes-*package or a localstubs/folder. Confidence: 0.85 - Use
@overloadonly when the return type truly depends on argument types; otherwise simplify the API. Confidence: 0.70 - Prefer PEP 695 syntax (
def first[T](xs: list[T]) -> T) on Python 3.12+ instead of module-levelTypeVardeclarations. Confidence: 0.75 - Annotate
self-returning builder methods withSelfrather than a boundTypeVar. Confidence: 0.80 - Mark constants with
Finaland override methods with@overrideso refactors surface mistakes. Confidence: 0.70 - Do not add runtime type checks that duplicate the static checker; validate only untrusted input at the edges. Confidence: 0.80
- Keep annotations import-cheap: put heavy imports under
if TYPE_CHECKING:to avoid circular imports and slow startup. Confidence: 0.75
Source and license
- Source
- Prompts Chat
- Original
- f/awesome-chatgpt-prompts/prompts.csv#python-type-hints-taste
- License
- MIT