Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Short form of enum.StrEnum fails #946

Open
dave-shawley opened this issue Nov 30, 2024 · 3 comments
Open

Short form of enum.StrEnum fails #946

dave-shawley opened this issue Nov 30, 2024 · 3 comments
Assignees

Comments

@dave-shawley
Copy link

Pyre Bug

Bug description

Similar to #698 only using enum.StrEnum in place of enum.Enum.

Reproduction steps

import enum

Color = enum.StrEnum('Color', ['Red', 'Blue'])
print(Color.Red)

Expected behavior

Type checking works.

Logs
Please include any relevant logs here:

ƛ No watchman binary found.
To enable pyre incremental, you can install watchman: https://facebook.github.io/watchman/docs/install
ƛ Defaulting to non-incremental check.
ƛ Found 2 type errors!
checkit.py:3:8 Too many arguments [19]: Call `enum.StrEnum.__new__` expects 1 positional argument, 2 were provided.
checkit.py:4:6 Undefined attribute [16]: `enum.StrEnum` has no attribute `Red`.
zsh: exit 1     pyre

Please run your reproduction steps followed by pyre rage > pyre_rage.log, and upload the file here:

pyre_rage.log

Additional context

Using hatch to manage virtual environments and have pyre installed into the environment.

@yangdanny97 yangdanny97 self-assigned this Nov 30, 2024
@yangdanny97
Copy link
Contributor

Thanks for reporting this issue, I'll take a look next week

@yangdanny97
Copy link
Contributor

I can confirm that Pyre doesn't support functional syntax for any enums besides enum.Enum.

I could add support for StrEnum and IntEnum fairly quickly, but the current setup would need major changes to have it work for any enum subclass. So a general solution would need to wait till we're done making some architectural changes to the system.

@dave-shawley
Copy link
Author

@yangdanny97 if you are in the process of refactoring, I would wait to be honest. Especially since switching to the class syntax solves the issue. Thanks for the great tool!

facebook-github-bot pushed a commit that referenced this issue Dec 3, 2024
Summary:
Context: #946

Previously, Pyre only supported the functional declaration syntax for `enum.Enum` and not any of its subclasses. It's difficult to extend this to all subclasses due to this being handled in preprocessing, but this diff extends its support to `enum.StrEnum` and `enum.IntEnum` which is a fairly easy lift.

Reviewed By: stroxler

Differential Revision: D66669647

fbshipit-source-id: b4560e637a1806e195d21be7adcdf0e06ed4d016
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

No branches or pull requests

2 participants