'Why does the type-hinting for enum show an error on VS Code?
I've run into an issue where the expected return type (Enum
) and the actual return type do not match, even though they should.
The weird thing is that depending on the way that I write the return statement, the results are different.
The following picture explains this better:
The error message is:
"Expression of type "auto" cannot be assigned to return type "PaymentValidationStatus" "auto" is incompatible with "PaymentValidationStatus"Pylance(reportGeneralTypeIssues)"
The code is:
class PaymentValidationStatus(Enum):
ORDER_NOT_FOUND = auto()
ALREADY_PAID = auto()
PAYMENT_AMOUNT_DOEST_NOT_MATCH_ORDER_PRICE = auto()
COULD_NOT_PAY_ORDER = auto()
PAYMENT_OK = auto()
def some() -> PaymentValidationStatus:
return PaymentValidationStatus["PAYMENT_OK"]
def some2() -> PaymentValidationStatus:
return PaymentValidationStatus.PAYMENT_OK
The version of vscode, python and python extension are:
- VSCode: 1.67 (MacOS)
- Python: 3.10
- Python extension: v2022.6.0
Update:
I have tried this code in a clean project and it doesn't show any errors.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|