[ty] Model int and str enum value normalization#26349
Merged
charliermarsh merged 24 commits intoJun 27, 2026
Merged
Conversation
Typing conformance resultsNo changes detected ✅Current numbersThe percentage of diagnostics emitted that were expected errors held steady at 94.47%. The percentage of expected errors that received a diagnostic held steady at 89.19%. The number of fully passing files held steady at 95/134. |
Memory usage reportMemory usage unchanged ✅ |
|
| Lint rule | Added | Removed | Changed |
|---|---|---|---|
invalid-argument-type |
0 | 7 | 0 |
| Total | 0 | 7 | 0 |
Raw diff:
schemathesis (https://github.com/schemathesis/schemathesis)
- src/schemathesis/generation/overrides.py:75:59 error[invalid-argument-type] Argument to function `lookup_parameter` is incorrect: Expected `str`, found `Literal["query", "header", "path", "cookie", "body"] | None`
- src/schemathesis/generation/dictionaries.py:112:73 error[invalid-argument-type] Argument to function `_find_parameter_binding` is incorrect: Expected `str`, found `Literal["query", "header", "path", "cookie", "body"] | None`
- src/schemathesis/generation/dictionaries.py:115:97 error[invalid-argument-type] Argument to function `_find_parameter_binding` is incorrect: Expected `str`, found `Literal["query", "header", "path", "cookie", "body"] | None`
- src/schemathesis/generation/dictionaries.py:230:21 error[invalid-argument-type] Argument is incorrect: Expected `str`, found `Literal["query", "header", "path", "cookie", "body"] | None`
- src/schemathesis/specs/openapi/extra_data_source.py:181:9 error[invalid-argument-type] Argument is incorrect: Expected `str`, found `Literal["query", "header", "path", "cookie", "body"] | None`
- src/schemathesis/specs/openapi/extra_data_source.py:199:9 error[invalid-argument-type] Argument is incorrect: Expected `str`, found `Literal["query", "header", "path", "cookie", "body"] | None`
- src/schemathesis/specs/openapi/extra_data_source.py:645:38 error[invalid-argument-type] Argument to bound method `list.append` is incorrect: Expected `tuple[str, str]`, found `tuple[Literal["query", "header", "path", "cookie", "body"] | None, str]`
Merging this PR will not alter performance
Comparing Footnotes
|
charliermarsh
force-pushed
the
charlie/normalize-built-in-enum-mixin-values
branch
from
June 25, 2026 02:01
e443c06 to
99e6ef0
Compare
charliermarsh
force-pushed
the
charlie/fix-enum-value-metadata
branch
2 times, most recently
from
June 25, 2026 02:05
65f063a to
1599879
Compare
charliermarsh
force-pushed
the
charlie/normalize-built-in-enum-mixin-values
branch
from
June 25, 2026 02:05
99e6ef0 to
70a659b
Compare
charliermarsh
marked this pull request as ready for review
June 25, 2026 22:58
charliermarsh
force-pushed
the
charlie/fix-enum-value-metadata
branch
from
June 25, 2026 23:02
1599879 to
6ce7e33
Compare
charliermarsh
force-pushed
the
charlie/normalize-built-in-enum-mixin-values
branch
from
June 25, 2026 23:03
70a659b to
579b61b
Compare
charliermarsh
force-pushed
the
charlie/normalize-built-in-enum-mixin-values
branch
from
June 25, 2026 23:14
579b61b to
193d068
Compare
charliermarsh
marked this pull request as draft
June 25, 2026 23:22
charliermarsh
force-pushed
the
charlie/normalize-built-in-enum-mixin-values
branch
from
June 26, 2026 00:49
2f27190 to
532e2cd
Compare
charliermarsh
force-pushed
the
charlie/normalize-built-in-enum-mixin-values
branch
3 times, most recently
from
June 26, 2026 14:39
146ef8b to
80c7281
Compare
charliermarsh
force-pushed
the
charlie/normalize-built-in-enum-mixin-values
branch
from
June 26, 2026 15:27
3fed494 to
a4f16cb
Compare
charliermarsh
changed the base branch from
main
to
charlie/detect-inherited-enum-new-member
June 26, 2026 15:27
charliermarsh
marked this pull request as ready for review
June 26, 2026 15:51
charliermarsh
added a commit
that referenced
this pull request
Jun 27, 2026
## Summary
When creating an enum class, CPython checks an inherited
`__new_member__` before falling back to an inherited `__new__` or the
data-type constructor. We previously skipped that lookup, so a parent
enum could replace `_value_` while we continued to expose the member's
declared right-hand side as its precise `.value` type.
This change includes inherited `__new_member__` in enum constructor
discovery. When that hook is user-defined, member values now use the
same conservative inference as other custom construction paths:
```python
from enum import Enum
class Base(Enum):
def __new_member__(cls: type["Base"], value: int) -> "Base":
obj = object.__new__(cls)
obj._value_ = str(value)
return obj
class Child(Base):
VALUE = 1
reveal_type(Child.VALUE.value) # Any
```
This is split out from #26349 so constructor discovery can land
independently of built-in enum mixin normalization.
Base automatically changed from
charlie/detect-inherited-enum-new-member
to
main
June 27, 2026 02:45
charliermarsh
force-pushed
the
charlie/normalize-built-in-enum-mixin-values
branch
from
June 27, 2026 03:19
a4f16cb to
9c736d1
Compare
charliermarsh
enabled auto-merge (squash)
June 27, 2026 03:48
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
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
For enums that inherit from
intorstr, Python converts each assigned value before storing it.For example:
Python converts
Falseto0. Therefore:Number.FALSE.valueis0, notFalse.Number.ZEROis another name forNumber.FALSE, not a separate member.Previously, we reasoned from the values as written (
Falseand0) and could incorrectly treat them as different members. We now account for the conversion performed byintorstr. And when we can't reliably predict it, we return a less precise type.