Skip to content

Fix Attrs method annotation evaluation#122

Open
iliyasone wants to merge 1 commit into
vercel:mainfrom
iliyasone:bugfix/attrs-skip-method-annotations
Open

Fix Attrs method annotation evaluation#122
iliyasone wants to merge 1 commit into
vercel:mainfrom
iliyasone:bugfix/attrs-skip-method-annotations

Conversation

@iliyasone
Copy link
Copy Markdown
Contributor

As I understand, Attrs[T] should inspect only class attributes, not methods. Previously, the Attrs path still called get_local_defns() in a mode that processed methods, which could execute PEP 649 __annotate__ functions before Attrs filtered anything out.

The problem is that some methods may not have good runtime annotations. For example, something like this:

if TYPE_CHECKING:
    class HiddenNamespace:
        pass

class Base:
    def rebuild(self, ns: HiddenNamespace | None = None) -> bool | None:
        return None

class Model(Base):
    name: str

Attrs[Model] should evaluate only Model.name and not raise an error, as evaluation of methods is not required for the Attribute types.

The bigger problem is that the runtime can't run the insides of the if TYPE_CHECKING block, and i guess there is nothing we can do about this

@vercel
Copy link
Copy Markdown

vercel Bot commented May 26, 2026

@iliyasone is attempting to deploy a commit to the Vercel Labs Team on Vercel.

A member of the Team first needs to authorize it.

Attrs should collect class attributes without resolving ordinary method
annotations. Thread an include_methods flag into get_local_defns and disable
method processing from the attrs_only path.

Add a regression test covering a method annotation that references a
TYPE_CHECKING-only name.
@iliyasone iliyasone force-pushed the bugfix/attrs-skip-method-annotations branch from 5b14848 to cf768d1 Compare May 27, 2026 00:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant