Is there a way to type a set of explicit values (that are of type int)? For example, I want to type that a variable can be from the set {0, 1, 2}
? (the numbers are actually mapped from constants)
Python explicit values for int variables
Userlevel 2
You can use literal types with mypy if you’re in Python 3.8+: https://mypy.readthedocs.io/en/latest/literal_types.html
Reply
Login to the community
No account yet? Create an account
Enter your username or e-mail address. We'll send you an e-mail with instructions to reset your password.