Skip to content

Conversation

tjdcs
Copy link
Owner

@tjdcs tjdcs commented Jul 14, 2025

Summary

  • Add missing _add_value_alias_ method to Enum class for Python 3.13
  • Add comprehensive test cases for the MultiValueEnum pattern

Fixes python#14408 by resolving the type checker error when using _add_value_alias_ method in Python 3.13 enum classes.

Changes Made

  • Added _add_value_alias_(self, value: Any) -> None method to Enum class in stdlib/enum.pyi
  • Added proper Python 3.13 version guard (if sys.version_info >= (3, 13):)
  • Added comprehensive test cases in stdlib/@tests/test_cases/check_enum.py including:
    • MultiValueEnum pattern from Python documentation
    • Type inference tests for primary and alias values
    • Literal type verification

Test Plan

  • Verify Pyright recognizes the method without errors (0 errors, 0 warnings)
  • Verify mypy recognizes the method without errors (Success: no issues found)
  • Test runtime functionality with Python 3.13 (✅ Works correctly)
  • Ensure no regressions in existing enum functionality (✅ All tests pass)
  • Test cases pass with both type checkers (✅ Pyright and mypy both succeed)

Example Usage

from enum import Enum

class MultiValueEnum(Enum):
    def __new__(cls, value, *values):
        self = object.__new__(cls)
        self._value_ = value
        for v in values:
            self._add_value_alias_(v)  # No longer causes type error
        return self

class DType(MultiValueEnum):
    float32 = 'f', 8
    double64 = 'd', 9

# Both work correctly
print(DType('f'))  # <DType.float32: 'f'>
print(DType(8))    # <DType.float32: 'f'>

🤖 Generated with Claude Code

Fixes python#14408 by adding the _add_value_alias_ method to the Enum class
with proper Python 3.13 version guard. Also adds comprehensive test
cases for the MultiValueEnum pattern.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@tjdcs
Copy link
Owner Author

tjdcs commented Jul 14, 2025

Closing this PR as it was created against the wrong repository. The correct PR is now at python#14411

@tjdcs tjdcs closed this Jul 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Missing attribute _add_value_alias_ for Enum
1 participant