[ty] Support for custom _generate_next_value_ in enums#25196
Conversation
_generate_next_value_ in enums
Typing conformance resultsNo changes detected ✅Current numbersThe percentage of diagnostics emitted that were expected errors held steady at 89.36%. The percentage of expected errors that received a diagnostic held steady at 85.49%. The number of fully passing files held steady at 88/134. |
Memory usage reportSummary
Significant changesClick to expand detailed breakdownprefect
sphinx
trio
flake8
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 89ca803ca6
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
| Project | Old Time | New Time | Change |
|---|---|---|---|
pandas-stubs |
9.73s | 14.72s | +51% |
89ca803 to
3f8aeba
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3f8aeba876
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
e756d3a to
b12a65b
Compare
…25210) ## Summary One oversight in my changes to #25196: if a custom `__new__` is defined, we should treat the alias value as `Any`, rather than relying on `_generate_next_value_`. This matches Pyright, for example. E.g., given: ```python class E(Enum): @staticmethod def _generate_next_value_(...) -> Literal["x"]: return "x" def __new__(cls, value: str): obj = object.__new__(cls) obj._value_ = object() return obj A = auto() B = auto() ``` Prior to this change, we treated `B` as an alias of `A`; but if `__new__` is defined, we don't attempt to detect the alias.
…5196) ## Summary astral-sh/ty#876 This PR adds support for custom `_generate_next_value_` methods on enums. When set, this return type will take precedence over inferred `auto()` member types unless an explicit `_value_` annotation is set. Falls back to `Any` if custom hooks (like `__init__`) are detected. References: - https://typing.python.org/en/latest/spec/enums.html#member-values - https://docs.python.org/3/library/enum.html#enum.Enum._generate_next_value_ ## Test Plan New mdtests --------- Co-authored-by: Charlie Marsh <charlie.r.marsh@gmail.com>
…stral-sh#25210) ## Summary One oversight in my changes to astral-sh#25196: if a custom `__new__` is defined, we should treat the alias value as `Any`, rather than relying on `_generate_next_value_`. This matches Pyright, for example. E.g., given: ```python class E(Enum): @staticmethod def _generate_next_value_(...) -> Literal["x"]: return "x" def __new__(cls, value: str): obj = object.__new__(cls) obj._value_ = object() return obj A = auto() B = auto() ``` Prior to this change, we treated `B` as an alias of `A`; but if `__new__` is defined, we don't attempt to detect the alias.
Summary
astral-sh/ty#876
This PR adds support for custom
_generate_next_value_methods on enums.When set, this return type will take precedence over inferred
auto()member types unless an explicit_value_annotation is set.Falls back to
Anyif custom hooks (like__init__) are detected.References:
Test Plan
New mdtests