Skip to content

[ty] functional enum syntax#23602

Open
thejchap wants to merge 4 commits intoastral-sh:mainfrom
thejchap:thejchap/enum-func-syntax
Open

[ty] functional enum syntax#23602
thejchap wants to merge 4 commits intoastral-sh:mainfrom
thejchap:thejchap/enum-func-syntax

Conversation

@thejchap
Copy link
Copy Markdown
Contributor

@thejchap thejchap commented Feb 27, 2026

Summary

astral-sh/ty#876
https://typing.python.org/en/latest/spec/enums.html#enum-definition

this pr implements the functional syntax for creating enums: Enum('Color2', 'RED, GREEN, BLUE')

it mostly copies the namedtuple implementation

it supports the start= and type= kwargs for Enum as well (docs)

it also supports Flag and IntFlag

the ddtrace diffs look to be correct - IntEnum call is now properly recognized

for non-string-literal name arguments, it falls back to just returning type[Enum] - this came up by way of a psycopg regression on this line - wasn't sure if this was better or worse than returning a DynamicEnumLiteral with an unknown name and members.

this now looks correct for psycopg: + psycopg/psycopg/types/enum.py:173:12 [error] [invalid-return-type] Return type does not match returned value: expected Enum, found type[Enum]``

however, it appears mypy does not correctly support the functional API (i am wondering if this is why the psycopg typing is the way it is), or maybe when just returning the result of the Enum call (without assigning it to a name), it always assumes its looking up a member:

from enum import Enum, EnumType
from typing import reveal_type


def make_color_1() -> EnumType:
    return Enum("Color1", names="RED GREEN")


def make_color_2() -> EnumType:
    return Enum("Color2", names=("RED", "GREEN"))


reveal_type(make_color_1())
reveal_type(make_color_2())
# mypy output

main.py:6: error: Incompatible return value type (got "Enum", expected "EnumMeta")  [return-value]
main.py:10: error: Incompatible return value type (got "Enum", expected "EnumMeta")  [return-value]
main.py:13: note: Revealed type is "enum.EnumMeta"
main.py:14: note: Revealed type is "enum.EnumMeta"
Found 2 errors in 1 file (checked 1 source file)

# runtime output
Runtime type is 'EnumType'
Runtime type is 'EnumType'

Test Plan

mdtests

@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot bot commented Feb 27, 2026

Typing conformance results improved 🎉

The percentage of diagnostics emitted that were expected errors increased from 87.72% to 87.75%. The percentage of expected errors that received a diagnostic increased from 82.85% to 82.88%. The number of fully passing files held steady at 74/132.

Summary

How are test cases classified?

Each test case represents one expected error annotation or a group of annotations sharing a tag. Counts are per test case, not per diagnostic — multiple diagnostics on the same line count as one. Required annotations (E) are true positives when ty flags the expected location and false negatives when it does not. Optional annotations (E?) are true positives when flagged but true negatives (not false negatives) when not. Tagged annotations (E[tag]) require ty to flag exactly one of the tagged lines; tagged multi-annotations (E[tag+]) allow any number up to the tag count. Flagging unexpected locations counts as a false positive.

Metric Old New Diff Outcome
True Positives 879 881 +2 ⏫ (✅)
False Positives 123 123 +0
False Negatives 182 182 +0
Total Diagnostics 1052 1054 +2
Precision 87.72% 87.75% +0.02% ⏫ (✅)
Recall 82.85% 82.88% +0.03% ⏫ (✅)
Passing Files 74/132 74/132 +0

Test file breakdown

1 file altered
File True Positives False Positives False Negatives Status
enums_definition.py 2 (+2) ✅ 0 0 ✅ Still Passing
Total (all files) 881 (+2) ✅ 123 182 74/132

Optional Diagnostics Added (2)

2 diagnostics
Test case Diff

enums_definition.py:24

+error[too-many-positional-arguments] Too many positional arguments to function `Enum`: expected 2, got 4

enums_definition.py:33

+error[invalid-type-form] Type arguments for `Literal` must be `None`, a literal value (int, bool, str, or bytes), or an enum member

@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot bot commented Feb 27, 2026

mypy_primer results

Changes were detected when running on open source projects
bidict (https://github.com/jab/bidict)
+ bidict/_base.py:400:22: error[invalid-argument-type] Argument to bound method `__delitem__` is incorrect: Expected `KT@BidictBase`, found `KT@BidictBase | MissingT`
+ bidict/_base.py:401:22: error[invalid-argument-type] Argument to bound method `__delitem__` is incorrect: Expected `VT@BidictBase`, found `VT@BidictBase | MissingT`
+ bidict/_base.py:411:22: error[invalid-argument-type] Argument to bound method `__delitem__` is incorrect: Expected `VT@BidictBase`, found `VT@BidictBase | MissingT`
+ bidict/_base.py:421:22: error[invalid-argument-type] Argument to bound method `__delitem__` is incorrect: Expected `KT@BidictBase`, found `KT@BidictBase | MissingT`
+ bidict/_bidict.py:143:20: error[invalid-return-type] Return type does not match returned value: expected `VT@MutableBidict | DT@pop`, found `DT@pop | MissingT`
- Found 18 diagnostics
+ Found 23 diagnostics

psycopg (https://github.com/psycopg/psycopg)
+ psycopg/psycopg/types/enum.py:173:12: error[invalid-return-type] Return type does not match returned value: expected `Enum`, found `<class '<unknown>'>`
- Found 669 diagnostics
+ Found 670 diagnostics

discord.py (https://github.com/Rapptz/discord.py)
+ discord/http.py:571:53: error[invalid-argument-type] Argument to bound method `ws_connect` is incorrect: Expected `ClientWSTimeout | _SENTINEL`, found `BasicAuth | None | str | ... omitted 4 union elements`
- Found 558 diagnostics
+ Found 559 diagnostics

scikit-build-core (https://github.com/scikit-build/scikit-build-core)
+ src/scikit_build_core/build/wheel.py:99:20: error[no-matching-overload] No overload of bound method `__init__` matches arguments
- Found 59 diagnostics
+ Found 60 diagnostics

core (https://github.com/home-assistant/core)
- homeassistant/components/http/forwarded.py:213:47: warning[unused-type-ignore-comment] Unused blanket `type: ignore` directive
- Found 12090 diagnostics
+ Found 12089 diagnostics

@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot bot commented Feb 27, 2026

Memory usage report

Summary

Project Old New Diff Outcome
flake8 47.93MB 47.94MB +0.03% (15.01kB)
trio 117.51MB 117.52MB +0.01% (11.20kB)
prefect 715.72MB 715.72MB -0.00% (144.00B) ⬇️
sphinx 263.86MB 263.86MB -0.00% (2.27kB) ⬇️

Significant changes

Click to expand detailed breakdown

flake8

Name Old New Diff Outcome
infer_expression_types_impl 1.05MB 1.05MB +0.18% (1.98kB)
Type<'db>::member_lookup_with_policy_ 493.21kB 494.78kB +0.32% (1.57kB)
StaticClassLiteral<'db>::implicit_attribute_inner_ 313.45kB 314.69kB +0.40% (1.24kB)
all_narrowing_constraints_for_expression 82.03kB 83.11kB +1.31% (1.08kB)
infer_scope_types_impl 992.99kB 993.92kB +0.09% (948.00B)
Type<'db>::class_member_with_policy_ 580.04kB 580.89kB +0.15% (872.00B)
StaticClassLiteral<'db>::try_mro_ 323.29kB 324.05kB +0.23% (772.00B)
Type<'db>::apply_specialization_ 218.44kB 219.06kB +0.29% (640.00B)
Type<'db>::try_call_dunder_get_ 376.18kB 376.74kB +0.15% (580.00B)
Specialization 163.03kB 163.55kB +0.32% (528.00B)
Type<'db>::class_member_with_policy_::interned_arguments 311.80kB 312.30kB +0.16% (520.00B)
is_redundant_with_impl 133.22kB 133.63kB +0.31% (420.00B)
Type<'db>::apply_specialization_::interned_arguments 204.61kB 205.00kB +0.19% (400.00B)
all_negative_narrowing_constraints_for_expression 39.61kB 39.98kB +0.95% (384.00B)
IntersectionType 67.09kB 67.45kB +0.54% (368.00B)
... 27 more

trio

Name Old New Diff Outcome
infer_expression_types_impl 7.03MB 7.03MB +0.04% (2.80kB)
infer_expression_type_impl 1.31MB 1.31MB +0.20% (2.64kB)
IntersectionType 215.77kB 217.59kB +0.84% (1.81kB)
is_redundant_with_impl::interned_arguments 528.09kB 529.89kB +0.34% (1.80kB)
all_negative_narrowing_constraints_for_expression 182.96kB 184.24kB +0.70% (1.28kB)
is_redundant_with_impl 464.54kB 465.47kB +0.20% (948.00B)
UnionType 300.11kB 300.73kB +0.21% (640.00B)
Type<'db>::class_member_with_policy_ 2.04MB 2.04MB -0.02% (496.00B)
Type<'db>::try_call_dunder_get_ 1.36MB 1.36MB -0.03% (496.00B)
infer_definition_types 7.63MB 7.63MB -0.01% (416.00B)
Type<'db>::class_member_with_policy_::interned_arguments 1.12MB 1.12MB -0.04% (416.00B)
UnionType<'db>::from_two_elements_ 281.56kB 281.94kB +0.13% (388.00B)
StaticClassLiteral<'db>::implicit_attribute_inner_ 750.50kB 750.80kB +0.04% (300.00B)
all_narrowing_constraints_for_expression 591.53kB 591.82kB +0.05% (300.00B)
Type<'db>::member_lookup_with_policy_ 1.83MB 1.83MB +0.02% (296.00B)
... 22 more

prefect

Name Old New Diff Outcome
StaticClassLiteral<'db>::is_typed_dict_ 626.34kB 626.16kB -0.03% (180.00B) ⬇️
infer_definition_types 89.62MB 89.62MB +0.00% (36.00B) ⬇️

sphinx

Name Old New Diff Outcome
Type<'db>::class_member_with_policy_ 7.70MB 7.70MB -0.01% (496.00B) ⬇️
Type<'db>::try_call_dunder_get_ 4.95MB 4.95MB -0.01% (496.00B) ⬇️
Type<'db>::class_member_with_policy_::interned_arguments 4.05MB 4.05MB -0.01% (416.00B) ⬇️
enum_metadata 738.52kB 738.29kB -0.03% (240.00B) ⬇️
StaticClassLiteral<'db>::is_typed_dict_ 183.75kB 183.57kB -0.10% (180.00B) ⬇️
Type<'db>::member_lookup_with_policy_ 6.54MB 6.54MB -0.00% (136.00B) ⬇️
Type<'db>::member_lookup_with_policy_::interned_arguments 2.68MB 2.68MB -0.00% (104.00B) ⬇️
Type<'db>::try_call_dunder_get_::interned_arguments 1.22MB 1.22MB -0.01% (104.00B) ⬇️
enum_ignored_names 3.19kB 3.09kB -2.94% (96.00B) ⬇️
BoundMethodType 708.98kB 708.91kB -0.01% (80.00B) ⬇️
infer_definition_types 23.82MB 23.82MB +0.00% (36.00B) ⬇️
infer_scope_types_impl 15.48MB 15.48MB -0.00% (12.00B) ⬇️

@ntBre ntBre added the ty Multi-file analysis & type inference label Feb 27, 2026
@charliermarsh charliermarsh self-assigned this Feb 27, 2026
@thejchap thejchap force-pushed the thejchap/enum-func-syntax branch 2 times, most recently from dbb7622 to da0c825 Compare February 28, 2026 06:11
@thejchap thejchap force-pushed the thejchap/enum-func-syntax branch 2 times, most recently from e3f84c6 to 5eae9a2 Compare March 10, 2026 04:07
@thejchap thejchap marked this pull request as ready for review March 10, 2026 04:15
@astral-sh-bot astral-sh-bot bot requested a review from charliermarsh March 10, 2026 04:15
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5eae9a2f9b

ℹ️ 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".

@carljm carljm removed their request for review March 11, 2026 05:17
@thejchap thejchap force-pushed the thejchap/enum-func-syntax branch from 5eae9a2 to 1baf73c Compare March 21, 2026 12:57
@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot bot commented Mar 21, 2026

ecosystem-analyzer results

Lint rule Added Removed Changed
invalid-argument-type 3 0 0
unresolved-attribute 0 3 0
call-non-callable 0 1 0
invalid-return-type 1 0 0
Total 4 4 0

Raw diff:

core (https://github.com/home-assistant/core)
+ homeassistant/components/http/forwarded.py:213:33 error[invalid-argument-type] Argument to bound method `clone` is incorrect: Expected `Mapping[str, str] | Mapping[istr, str] | Iterable[tuple[str, str]] | _SENTINEL`, found `str`
+ homeassistant/components/http/forwarded.py:213:33 error[invalid-argument-type] Argument to bound method `clone` is incorrect: Expected `int | _SENTINEL`, found `str`

dd-trace-py (https://github.com/DataDog/dd-trace-py)
- ddtrace/vendor/psutil/_psposix.py:56:16 error[call-non-callable] Object of type `IntEnum` is not callable
- ddtrace/vendor/psutil/_pslinux.py:96:11 error[unresolved-attribute] Object of type `IntEnum` has no attribute `AF_LINK`
- ddtrace/vendor/psutil/_pswindows.py:82:11 error[unresolved-attribute] Object of type `IntEnum` has no attribute `AF_LINK`

discord.py (https://github.com/Rapptz/discord.py)
+ discord/http.py:571:53 error[invalid-argument-type] Argument to bound method `ws_connect` is incorrect: Expected `ClientWSTimeout | _SENTINEL`, found `ClientWSTimeout | float`

psycopg (https://github.com/psycopg/psycopg)
+ psycopg/psycopg/types/enum.py:173:12 error[invalid-return-type] Return type does not match returned value: expected `Enum`, found `type[Enum]`

pybind11 (https://github.com/pybind/pybind11)
- tests/test_native_enum.py:117:41 error[unresolved-attribute] Object of type `IntEnum` has no attribute `mem`

Full report with detailed diff (timing results)

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1baf73cfe0

ℹ️ 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".

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 893448a30b

ℹ️ 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".

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d41b7b9b4b

ℹ️ 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".

@thejchap thejchap force-pushed the thejchap/enum-func-syntax branch from 3cc298d to 33a4cb3 Compare March 22, 2026 15:36
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 33a4cb37a6

ℹ️ 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".

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 25b76f106b

ℹ️ 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".

@thejchap thejchap marked this pull request as draft March 22, 2026 18:12
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: de88e98c1e

ℹ️ 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".

@thejchap thejchap marked this pull request as ready for review March 24, 2026 02:10
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d08281f5f3

ℹ️ 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".

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 996f83631b

ℹ️ 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".

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1d6af9dab3

ℹ️ 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".

@charliermarsh
Copy link
Copy Markdown
Member

Thank you for working on this. I'm going to wait to review until we land functional TypedDict support (#24174) since we'll then need to rebase here and it may establish some useful patterns / precedents.

@thejchap thejchap force-pushed the thejchap/enum-func-syntax branch from 1d6af9d to 0cb327a Compare March 30, 2026 02:14
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0cb327a20b

ℹ️ 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".

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3390f5411c

ℹ️ 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".

@thejchap thejchap force-pushed the thejchap/enum-func-syntax branch from 3390f54 to f7d9ce2 Compare April 1, 2026 21:17
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f7d9ce23b1

ℹ️ 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".

@thejchap thejchap force-pushed the thejchap/enum-func-syntax branch 2 times, most recently from 758cda5 to b3d444a Compare April 5, 2026 20:01
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b3d444afeb

ℹ️ 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".

@thejchap thejchap force-pushed the thejchap/enum-func-syntax branch from b3d444a to c31e542 Compare April 5, 2026 20:14
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c31e5427a4

ℹ️ 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".

@charliermarsh
Copy link
Copy Markdown
Member

charliermarsh commented Apr 6, 2026

Here's a diff with some tests demonstrating current behavior on this branch as compared to static Enum: 6ee61c3.

(You don't need to commit these exact tests verbatim with the static Enum comparisons; this is just for illustration.)

We should review each case where we're diverging from static Enum and figure out if we can get the two in-line. For cases that static Enum already gets "wrong", we should add a test for functional Enum with a TODO.

@charliermarsh
Copy link
Copy Markdown
Member

I'm wondering if the shape here should be closer to functional TypedDict and type(...) whereby we defer inference of various fields (like type). But I haven't been able to come up with a real, runtime-valid example where that matters. Did you consider it?

@thejchap thejchap force-pushed the thejchap/enum-func-syntax branch from c31e542 to 3dd7d3a Compare April 8, 2026 22:57
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3dd7d3a8c7

ℹ️ 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".

@thejchap
Copy link
Copy Markdown
Contributor Author

thejchap commented Apr 9, 2026

we defer inference of various fields ... Did you consider it?

truthfully i hadn't considered it - let me just make sure i understand

for TypedDict we want to defer field type inference until after scope inference because of valid forward-declaration situations like this:

Line = TypedDict('Line', {'start': Point, 'end': Point})
Point = TypedDict('Point', {'x': int, 'y': int})

for Enums, a contrived/invalid example would be something like:

Color = Enum('Color', {'RED': BASE, 'GREEN': BASE + 1, 'BLUE': BASE + 2})
BASE = 10

but to your point that's not a runtime-valid example

either way, i'll defer to you - if there are other reasons to reimplement using deferred inference (consistency with TypedDict or anything else) i'm happy to do so!

still need to work through the static enum parity comment but otherwise i think i got the rest of the pr feedback

@thejchap thejchap force-pushed the thejchap/enum-func-syntax branch from 3dd7d3a to 49a4939 Compare April 9, 2026 02:15
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 49a4939e7e

ℹ️ 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".

@charliermarsh
Copy link
Copy Markdown
Member

As an example of deferred inference, you need to defer the fields to support cases like:

Tree = TypedDict(
    "Tree",
    {
        "value": int,
        "left": "Tree | None",
        "right": "Tree | None",
    },
)

So generally it's only needed to support type annotation on the right-hand side. It seems like the type= field accepts an annotation... but it doesn't accept forward references, since it needs to be accessible at runtime? In which case, we shouldn't need to defer.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bde7eb43b9

ℹ️ 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".

@thejchap
Copy link
Copy Markdown
Contributor Author

thejchap commented Apr 9, 2026

hmm i don't think it even takes an annotation

`type`, if set, will be mixed in as the first base class.
- just a plain class object

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.

3 participants