FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Add `EnumMeta.__prepare__` by AlexWaygood · Pull Request #7243 · python/typeshed · GitHub

Repository navigation

Add EnumMeta.__prepare__ - #7243

Merged
JelleZijlstra merged 1 commit into
python:masterfrom
AlexWaygood:__prepare__
Feb 20, 2022
Merged

JelleZijlstra merged 1 commit into
python:masterfrom
AlexWaygood:__prepare__

Conversation

Copy link
Copy Markdown
Member

I don't really understand why this needs the # type: ignores, but mypy seems absolutely convinced that this method breaks LSP!

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

hauntsaninja left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

It breaks LSP on 3.8 by not accepting **kwds, not sure about on 3.9 (will check the PR out locally later and see)

Copy link
Copy Markdown
Collaborator

Looking into the LSP complaint on 3.9:

stdlib/enum.pyi:85: error: Signature of "__prepare__" incompatible with supertype "type"  [override]
stdlib/enum.pyi:85: note:      Superclass:
stdlib/enum.pyi:85: note:          def __prepare__(metacls, str, Tuple[type, ...], **kwds: Any) -> Mapping[str, object]
stdlib/enum.pyi:85: note:      Subclass:
stdlib/enum.pyi:85: note:          @classmethod
stdlib/enum.pyi:85: note:          def __prepare__(metacls, cls: str, bases: Tuple[type, ...], **kwds: Any) -> _EnumDict

It goes away if you mark the args as positional-only, which seems incorrect:

diff --git a/stdlib/enum.pyi b/stdlib/enum.pyi
index 8ca0a5f8..0c4a2943 100644
--- a/stdlib/enum.pyi
+++ b/stdlib/enum.pyi
@@ -82,7 +82,7 @@ class EnumMeta(ABCMeta):
 
     if sys.version_info >= (3, 9):
         @classmethod
-        def __prepare__(metacls, cls: str, bases: tuple[type, ...], **kwds: Any) -> _EnumDict: ...  # type: ignore[override]
+        def __prepare__(metacls, __cls: str, __bases: tuple[type, ...], **kwds: Any) -> _EnumDict: ...
     else:
         @classmethod
         def __prepare__(metacls, cls: str, bases: tuple[type, ...]) -> _EnumDict: ...  # type: ignore[override]

(Also the error message seems to drop the classmethod on the superclass, but based on tests I think that might just be a reporting issue). So I'm happy to chalk this up to mypy bug.

Copy link
Copy Markdown
Member

Thanks for checking! Wasn't there some bug where the @classmethod decorator in this message sometimes gets eaten by the cache? Anyway, this does look like a mypy bug.

hauntsaninja commented Feb 21, 2022 •
edited
Loading

Copy link
Copy Markdown
Collaborator

I mean I guess technically mypy has a point in that: x.__prepare__(metaclass, cls, bases, cls=100) will get you a TypeError if it turns out your x is an EnumMeta and not a type. But I'm guessing the complaint might not be intentional.

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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.

3 participants


Back | FazBrowse Home | New Git URL