STRUCT006infoPro

hasattr-getattr-pattern

Using hasattr/getattr for attribute access instead of proper typing.

Applies to: Python

Why this matters

Using hasattr() or getattr() to check for attributes usually means you're working around missing type information. If you're checking if a dataclass or object has a field, you probably need to define proper types or use Protocol/ABC. This loses IDE autocomplete and type checking benefits.

Catch it before it ships

pip install stablestack # or: npx stablestackstablestack # scans your project, STRUCT006 includedstablestack explain STRUCT006

STRUCT006 is part of the Pro rule set. See pricing — the free tier ships 24 checks with no signup.

False positive in your codebase? Suppress a single line with # noqa: STRUCT006