Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[ty] Infer precise values for standard-library enums#26103

Merged
charliermarsh merged 1 commit into
mainfrom
charlie/precise-intenum-values
Jun 17, 2026
Merged

[ty] Infer precise values for standard-library enums#26103
charliermarsh merged 1 commit into
mainfrom
charlie/precise-intenum-values

Conversation

@charliermarsh

Copy link
Copy Markdown
Member

Summary

Enum members with known standard-library constructors currently lose their precise value type whenever construction includes __new__ or __init__. For example, IntEnum.X.value is inferred as int even when the declared value is exactly 1.

This preserves literal values when their runtime class matches the enum's inherited _value_ annotation:

from enum import IntEnum

class Answer(IntEnum):
    YES = 1

reveal_type(Answer.YES.value)  # Literal[1]

Values that the constructor normalizes, such as True passed through int.__new__, continue to use the inherited annotation. User-defined _value_ annotations and constructors also retain their existing conservative behavior.

@astral-sh-bot astral-sh-bot Bot added the ty Multi-file analysis & type inference label Jun 17, 2026
@astral-sh-bot

astral-sh-bot Bot commented Jun 17, 2026

Copy link
Copy Markdown

Typing conformance results

No changes detected ✅

Current numbers
The percentage of diagnostics emitted that were expected errors held steady at 94.37%. The percentage of expected errors that received a diagnostic held steady at 89.00%. The number of fully passing files held steady at 94/134.

@astral-sh-bot

astral-sh-bot Bot commented Jun 17, 2026

Copy link
Copy Markdown

Memory usage report

Summary

Project Old New Diff Outcome
prefect 526.38MB 526.42MB +0.01% (48.77kB)
sphinx 198.86MB 198.87MB +0.01% (11.84kB)
trio 81.15MB 81.16MB +0.00% (3.86kB)
flake8 33.02MB 33.02MB +0.00% (1.19kB)

Significant changes

Click to expand detailed breakdown

prefect

Name Old New Diff Outcome
enum_metadata 2.32MB 2.36MB +2.00% (47.55kB)
all_narrowing_constraints_for_expression 6.56MB 6.56MB +0.00% (336.00B)
is_redundant_with_impl::interned_arguments 2.34MB 2.34MB +0.01% (176.00B)
member_lookup_with_policy_inner 14.25MB 14.25MB +0.00% (164.00B)
Type<'db>::class_member_with_policy_ 10.93MB 10.93MB +0.00% (152.00B)
member_lookup_with_policy_inner::interned_arguments 6.70MB 6.70MB +0.00% (120.00B)
Type<'db>::class_member_with_policy_::interned_arguments 5.70MB 5.70MB +0.00% (104.00B)
is_redundant_with_impl 1.93MB 1.93MB +0.00% (96.00B)
BoundMethodType 1.69MB 1.69MB +0.00% (80.00B)
infer_scope_types_impl 38.97MB 38.97MB +0.00% (32.00B)
infer_expression_types_impl 56.76MB 56.76MB -0.00% (12.00B)

sphinx

Name Old New Diff Outcome
enum_metadata 579.71kB 591.55kB +2.04% (11.84kB)

trio

Name Old New Diff Outcome
enum_metadata 208.28kB 212.14kB +1.85% (3.86kB)

flake8

Name Old New Diff Outcome
enum_metadata 57.08kB 58.27kB +2.08% (1.19kB)

@AlexWaygood AlexWaygood left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, assuming no ecosystem surprises

@astral-sh-bot

astral-sh-bot Bot commented Jun 17, 2026

Copy link
Copy Markdown

ecosystem-analyzer results

No diagnostic changes detected ✅

Full report with detailed diff (timing results)

@charliermarsh charliermarsh force-pushed the charlie/precise-intenum-values branch from 9d0d437 to 17b768a Compare June 17, 2026 14:47
@charliermarsh charliermarsh marked this pull request as ready for review June 17, 2026 14:58
@charliermarsh charliermarsh requested a review from a team as a code owner June 17, 2026 14:58
@astral-sh-bot astral-sh-bot Bot requested a review from carljm June 17, 2026 14:58
@charliermarsh charliermarsh merged commit 6d3a09b into main Jun 17, 2026
65 of 66 checks passed
@charliermarsh charliermarsh deleted the charlie/precise-intenum-values branch June 17, 2026 15:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants