Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork3.1k
Issue warning for enum with no members in stub#18068
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
This comment has been minimized.
This comment has been minimized.
Uh oh!
There was an error while loading.Please reload this page.
mypy/checker.py Outdated
| ifbase.is_enumandbase.fullnamenotinENUM_BASES: | ||
| self.check_final_enum(defn,base) | ||
| ifself.is_stubandnotself.is_typeshed_stubandself.tree.fullname!="enum": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Why do we need to exclude typeshed? Didn't we already fix this in typeshed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
This was before I added the check against enum.pyi specifically. Looks like I'd also need to silence_typeshed because it has some StrEnum stuff
Diff frommypy_primer, showing the effect of this PR on open source code: python-htmlgen (https://github.com/srittau/python-htmlgen)+ htmlgen/form.pyi:8: error: Detected enum "htmlgen.form.Autocomplete" in a type stub with zero members. There is a chance this is due to a recent change in the semantics of enum membership. If so, use `member = value` to mark an enum member, instead of `member: type` [misc]+ htmlgen/form.pyi:8: note: See https://typing.readthedocs.io/en/latest/spec/enums.html#defining-members+ htmlgen/video.pyi:6: error: Detected enum "htmlgen.video.Preload" in a type stub with zero members. There is a chance this is due to a recent change in the semantics of enum membership. If so, use `member = value` to mark an enum member, instead of `member: type` [misc]+ htmlgen/video.pyi:6: note: See https://typing.readthedocs.io/en/latest/spec/enums.html#defining-membersTanjun (https://github.com/FasterSpeeding/Tanjun)+ tanjun/_internal/vendor/inspect.pyi:196: error: Detected enum "tanjun._internal.vendor.inspect._ParameterKind" in a type stub with zero members. There is a chance this is due to a recent change in the semantics of enum membership. If so, use `member = value` to mark an enum member, instead of `member: type` [misc]+ tanjun/_internal/vendor/inspect.pyi:196: note: See https://typing.readthedocs.io/en/latest/spec/enums.html#defining-memberspandas (https://github.com/pandas-dev/pandas)+ pandas/_libs/tslibs/dtypes.pyi:31: error: Detected enum "pandas._libs.tslibs.dtypes.FreqGroup" in a type stub with zero members. There is a chance this is due to a recent change in the semantics of enum membership. If so, use `member = value` to mark an enum member, instead of `member: type` [misc]+ pandas/_libs/tslibs/dtypes.pyi:31: note: See https://typing.readthedocs.io/en/latest/spec/enums.html#defining-members+ pandas/_libs/tslibs/dtypes.pyi:48: error: Detected enum "pandas._libs.tslibs.dtypes.Resolution" in a type stub with zero members. There is a chance this is due to a recent change in the semantics of enum membership. If so, use `member = value` to mark an enum member, instead of `member: type` [misc]+ pandas/_libs/tslibs/dtypes.pyi:48: note: See https://typing.readthedocs.io/en/latest/spec/enums.html#defining-members+ pandas/_libs/tslibs/dtypes.pyi:70: error: Detected enum "pandas._libs.tslibs.dtypes.NpyDatetimeUnit" in a type stub with zero members. There is a chance this is due to a recent change in the semantics of enum membership. If so, use `member = value` to mark an enum member, instead of `member: type` [misc]+ pandas/_libs/tslibs/dtypes.pyi:70: note: See https://typing.readthedocs.io/en/latest/spec/enums.html#defining-membersdjango-stubs (https://github.com/typeddjango/django-stubs)+ django-stubs/db/models/constants.pyi:5: error: Detected enum "django.db.models.constants.OnConflict" in a type stub with zero members. There is a chance this is due to a recent change in the semantics of enum membership. If so, use `member = value` to mark an enum member, instead of `member: type` [misc]+ django-stubs/db/models/constants.pyi:5: note: See https://typing.readthedocs.io/en/latest/spec/enums.html#defining-members+ django-stubs/contrib/gis/gdal/srs.pyi:7: error: Detected enum "django.contrib.gis.gdal.srs.AxisOrder" in a type stub with zero members. There is a chance this is due to a recent change in the semantics of enum membership. If so, use `member = value` to mark an enum member, instead of `member: type` [misc]+ django-stubs/contrib/gis/gdal/srs.pyi:7: note: See https://typing.readthedocs.io/en/latest/spec/enums.html#defining-members+ django-stubs/template/base.pyi:28: error: Detected enum "django.template.base.TokenType" in a type stub with zero members. There is a chance this is due to a recent change in the semantics of enum membership. If so, use `member = value` to mark an enum member, instead of `member: type` [misc]+ django-stubs/template/base.pyi:28: note: See https://typing.readthedocs.io/en/latest/spec/enums.html#defining-members+ django-stubs/db/models/enums.pyi:44: error: Detected enum "django.db.models.enums.Choices" in a type stub with zero members. There is a chance this is due to a recent change in the semantics of enum membership. If so, use `member = value` to mark an enum member, instead of `member: type` [misc]+ django-stubs/db/models/enums.pyi:44: note: See https://typing.readthedocs.io/en/latest/spec/enums.html#defining-members+ django-stubs/db/models/enums.pyi:63: error: Detected enum "django.db.models.enums.IntegerChoices" in a type stub with zero members. There is a chance this is due to a recent change in the semantics of enum membership. If so, use `member = value` to mark an enum member, instead of `member: type` [misc]+ django-stubs/db/models/enums.pyi:63: note: See https://typing.readthedocs.io/en/latest/spec/enums.html#defining-members+ django-stubs/db/models/enums.pyi:79: error: Detected enum "django.db.models.enums.TextChoices" in a type stub with zero members. There is a chance this is due to a recent change in the semantics of enum membership. If so, use `member = value` to mark an enum member, instead of `member: type` [misc]+ django-stubs/db/models/enums.pyi:79: note: See https://typing.readthedocs.io/en/latest/spec/enums.html#defining-members+ django-stubs/db/models/constraints.pyi:12: error: Detected enum "django.db.models.constraints.Deferrable" in a type stub with zero members. There is a chance this is due to a recent change in the semantics of enum membership. If so, use `member = value` to mark an enum member, instead of `member: type` [misc]+ django-stubs/db/models/constraints.pyi:12: note: See https://typing.readthedocs.io/en/latest/spec/enums.html#defining-members+ django-stubs/contrib/admin/options.pyi:47: error: Detected enum "django.contrib.admin.options.ShowFacets" in a type stub with zero members. There is a chance this is due to a recent change in the semantics of enum membership. If so, use `member = value` to mark an enum member, instead of `member: type` [misc]+ django-stubs/contrib/admin/options.pyi:47: note: See https://typing.readthedocs.io/en/latest/spec/enums.html#defining-memberspandas-stubs (https://github.com/pandas-dev/pandas-stubs)+ pandas-stubs/core/interchange/dataframe_protocol.pyi:16: error: Detected enum "pandas.core.interchange.dataframe_protocol.DlpackDeviceType" in a type stub with zero members. There is a chance this is due to a recent change in the semantics of enum membership. If so, use `member = value` to mark an enum member, instead of `member: type` [misc]+ pandas-stubs/core/interchange/dataframe_protocol.pyi:16: note: See https://typing.readthedocs.io/en/latest/spec/enums.html#defining-members+ pandas-stubs/core/interchange/dataframe_protocol.pyi:26: error: Detected enum "pandas.core.interchange.dataframe_protocol.DtypeKind" in a type stub with zero members. There is a chance this is due to a recent change in the semantics of enum membership. If so, use `member = value` to mark an enum member, instead of `member: type` [misc]+ pandas-stubs/core/interchange/dataframe_protocol.pyi:26: note: See https://typing.readthedocs.io/en/latest/spec/enums.html#defining-members+ pandas-stubs/core/interchange/dataframe_protocol.pyi:35: error: Detected enum "pandas.core.interchange.dataframe_protocol.ColumnNullType" in a type stub with zero members. There is a chance this is due to a recent change in the semantics of enum membership. If so, use `member = value` to mark an enum member, instead of `member: type` [misc]+ pandas-stubs/core/interchange/dataframe_protocol.pyi:35: note: See https://typing.readthedocs.io/en/latest/spec/enums.html#defining-members+ pandas-stubs/_libs/tslibs/dtypes.pyi:31: error: Detected enum "pandas._libs.tslibs.dtypes.Resolution" in a type stub with zero members. There is a chance this is due to a recent change in the semantics of enum membership. If so, use `member = value` to mark an enum member, instead of `member: type` [misc]+ pandas-stubs/_libs/tslibs/dtypes.pyi:31: note: See https://typing.readthedocs.io/en/latest/spec/enums.html#defining-members |
| # `__members__` will always be overwritten by `Enum` and is considered | ||
| # read-only so we disallow assigning a value to it | ||
| self.fail(message_registry.ENUM_MEMBERS_ATTR_WILL_BE_OVERRIDEN,sym.node) | ||
| ifdefn.info.fullnamenotinENUM_BASESand"__members__"indefn.info.names: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
This is just an optimization because previously we were iterating over the whole dict unnecessarily, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Yup
58f7628 intopython:masterUh oh!
There was an error while loading.Please reload this page.
Seehttps://typing.readthedocs.io/en/latest/spec/enums.html#defining-memberspython/typing-council#11The next version of mypy will obey the spec change:python/mypy#18068pyright already requires this
Seehttps://typing.readthedocs.io/en/latest/spec/enums.html#defining-memberspython/typing-council#11The next version of mypy will obey the spec change:python/mypy#18068pyright already requires this
* Update enums to reflect typing spec changesSeehttps://typing.readthedocs.io/en/latest/spec/enums.html#defining-memberspython/typing-council#11The next version of mypy will obey the spec change:python/mypy#18068pyright already requires thisCo-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
* Update enums to reflect typing spec changesSeehttps://typing.readthedocs.io/en/latest/spec/enums.html#defining-memberspython/typing-council#11The next version of mypy will obey the spec change:python/mypy#18068pyright already requires this* warning* .* .
Uh oh!
There was an error while loading.Please reload this page.
Follow up to#17207