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

Flag Enum OR-ing gets flagged as not supported #726

Closed
CrazyIvan359 opened this issue Dec 13, 2020 · 2 comments
Closed

Flag Enum OR-ing gets flagged as not supported #726

CrazyIvan359 opened this issue Dec 13, 2020 · 2 comments
Labels
bug Something isn't working fixed in next version (main) A fix has been implemented and will appear in an upcoming version

Comments

@CrazyIvan359
Copy link

Environment data

  • Language Server version: 2020.12.2
  • OS and version: Ubuntu 20.04
  • Python version: 3.8.5
  • "python.analysis.typeCheckingMode": "strict"

Expected behaviour

Python Flag enums support setting an enum to the combination of other already defined enums using the | (OR) operator. This behaviour is shown in the documentation.

Pylance should not be flagging this as unsupported and marking the resulting value as an Unknown type. The resulting type should be along the lines of Literal[PinMode.INPUT | PinMode.OUTPUT] or Literal[PinMode[INPUT | OUTPUT]] (I think).

Actual behaviour

Pylance reports an error reportGeneralTypeIssues when using the | (OR) operator on flag type enums.

Code Snippet / Additional information

class PinMode(enum.Flag):
    """ Pin operating mode """

    INPUT = enum.auto()
    OUTPUT = enum.auto()
    DIGITAL = INPUT | OUTPUT # <-- this line gives the below error message
Operator "|" not supported for types "Literal[PinMode.INPUT]" and "Literal[PinMode.OUTPUT]"
  Operator "|" not supported for types "Literal[PinMode.INPUT]" and "Literal[PinMode.OUTPUT]"Pylance(reportGeneralTypeIssues)
@erictraut
Copy link
Contributor

Thanks for the bug report. This will be fixed in the next release.

@erictraut erictraut added bug Something isn't working fixed in next version (main) A fix has been implemented and will appear in an upcoming version and removed triage labels Dec 13, 2020
@jakebailey
Copy link
Member

This issue has been fixed in version 2021.1.0, which we've just released. You can find the changelog here: https://github.com/microsoft/pylance-release/blob/main/CHANGELOG.md#202110-6-january-2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed in next version (main) A fix has been implemented and will appear in an upcoming version
Projects
None yet
Development

No branches or pull requests

3 participants