Thanks to visit codestin.com
Credit goes to github.com

Skip to content

builtins: remove object.__annotations__ #14000

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

JelleZijlstra
Copy link
Member

Not all objects have annotations, so I think this shouldn't exist.
We already have __annotations__ attributes explicitly set on the
objects that do have them (e.g., functions, classes, and modules).

Not sure what the fallout of this is going to be; it might not be worth changing.

Not all objects have annotations, so I think this shouldn't exist.
We already have `__annotations__` attributes explicitly set on the
objects that do have them (e.g., functions, classes, and modules).

This comment has been minimized.

@JelleZijlstra
Copy link
Member Author

This seems promising, we'll just have to add __annotations__ to a few other classes.

@JelleZijlstra
Copy link
Member Author

The openlibrary change is a true positive, at least on 3.14 where accessing .__annotations__ on instances will no longer work. Submitted internetarchive/openlibrary#10753 to fix it.

Not sure about the steam.py one; it seems to be using annotations in an odd way. cc @Gobot1234

The other three should go away with the changes I'm about to push.

@Gobot1234
Copy link
Contributor

In steam.py I'm using it for data parsing I don't think my use case is crazy out of the ordinary but I can stomach adding __annotations__ to StructMessage

@JelleZijlstra
Copy link
Member Author

You might need to use type(self).__annotations__ but haven't looked deeply at the code.

@JelleZijlstra
Copy link
Member Author

CI breakage seems due to a release of click 20 minutes ago https://pypi.org/project/click/8.2.0/

Copy link
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

steam.py (https://github.com/Gobot1234/steam.py)
- steam/protobufs/struct_messages.py:24: error: Incompatible types in assignment (expression has type "tuple[()]", variable has type "dict[str, Any]")  [assignment]
+ steam/protobufs/struct_messages.py:22: error: "StructMessage" has no attribute "__annotations__"  [attr-defined]
+ steam/protobufs/struct_messages.py:29: error: "StructMessage" has no attribute "__annotations__"  [attr-defined]
- steam/ext/csgo/backpack.py:291: error: Definition of "SLOTS" in base class "DescriptionMixin" is incompatible with definition in base class "BaseItem"  [misc]

openlibrary (https://github.com/internetarchive/openlibrary)
+ openlibrary/plugins/upstream/table_of_contents.py: note: In member "extra_fields" of class "TocEntry":
+ openlibrary/plugins/upstream/table_of_contents.py:85: error: "TocEntry" has no attribute "__annotations__"  [attr-defined]
+ openlibrary/plugins/upstream/table_of_contents.py: note: In member "is_empty" of class "TocEntry":
+ openlibrary/plugins/upstream/table_of_contents.py:174: error: "TocEntry" has no attribute "__annotations__"  [attr-defined]

hydra-zen (https://github.com/mit-ll-responsible-ai/hydra-zen)
+ src/hydra_zen/third_party/pydantic.py:53: error: "_Wrapped[[VarArg(Any), KwArg(Any)], Any, [VarArg(Any), KwArg(Any)], Any]" has no attribute "__annotations__"  [attr-defined]

zulip (https://github.com/zulip/zulip)
+ corporate/lib/decorator.py:144: error: "_Wrapped[[HttpRequest, RemoteRealmBillingSession, **ParamT], HttpResponse, [HttpRequest, **ParamT], HttpResponse]" has no attribute "__annotations__"  [attr-defined]
+ corporate/lib/decorator.py:231: error: "_Wrapped[[HttpRequest, RemoteServerBillingSession, **ParamT], HttpResponse, [HttpRequest, **ParamT], HttpResponse]" has no attribute "__annotations__"  [attr-defined]

@JelleZijlstra JelleZijlstra marked this pull request as draft May 10, 2025 23:00
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.

2 participants