Skip to content

[ty] Ignore _generate_next_value_ with custom construction hooks#25210

Merged
charliermarsh merged 2 commits into
mainfrom
charlie/gennextvalue
May 17, 2026
Merged

[ty] Ignore _generate_next_value_ with custom construction hooks#25210
charliermarsh merged 2 commits into
mainfrom
charlie/gennextvalue

Conversation

@charliermarsh
Copy link
Copy Markdown
Member

@charliermarsh charliermarsh commented May 17, 2026

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:

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.

@astral-sh-bot astral-sh-bot Bot added the ty Multi-file analysis & type inference label May 17, 2026
@charliermarsh charliermarsh changed the title [ty] Ignore _generate_next_value_ with custom construction hooks [ty] Ignore _generate_next_value_ with custom construction hooks May 17, 2026
@charliermarsh charliermarsh added the bug Something isn't working label May 17, 2026
@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot Bot commented May 17, 2026

Typing conformance results

No changes detected ✅

Current numbers
The 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.

@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot Bot commented May 17, 2026

Memory usage report

Memory usage unchanged ✅

@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot Bot commented May 17, 2026

ecosystem-analyzer results

No diagnostic changes detected ✅

Full report with detailed diff (timing results)

@charliermarsh charliermarsh marked this pull request as ready for review May 17, 2026 22:48
@charliermarsh charliermarsh merged commit b81d55e into main May 17, 2026
59 checks passed
@charliermarsh charliermarsh deleted the charlie/gennextvalue branch May 17, 2026 22:48
thejchap pushed a commit to thejchap/ruff that referenced this pull request May 23, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants