Related to #2092
Python uses the convention that screaming snake_case global variables are constants while regular snake_case variables are mutable.
Type-checkers and linters have adopted this standard and use it to infer code behavior, e.g.
value = "A"
VALUE = "A"
def use_literal(x: Literal["A"]):
...
def check_const(x: str):
if x == VALUE:
# This passes type-checking
use_literal(x)
def check_mut(x: str):
if x == value:
# This fails because the type-checker assumes `value` can be reassigned
use_literal(x)
asdf uses snake_case global constants in a number of places that could be replaced with screaming snake_case.
Unfortunately there isn't really a good way to deprecate a global variable. Things like @deprecated or DeprecationWarning only work with a function or class.
The only way I'm aware of to do it is to create a custom module-level __getattr__ that can then raise a DeprecationWarning when the symbol is imported, but even that only works at runtime and doesn't have the nice in-IDE warnings that @deprecated does.
I guess the other option would be to rename the variable, add the old name as an alias pointing to the new name, transition the internal code to the new name, and then just never remove/deprecate the old variable name, e.g.
# Old
value = "A"
# New
VALUE = "A"
value = VALUE
The maintenance overhead of keeping the old name is pretty minimal.
Instances
Here is where I will track instances of this I've found to be fixed later:
Related to #2092
Python uses the convention that screaming snake_case global variables are constants while regular snake_case variables are mutable.
Type-checkers and linters have adopted this standard and use it to infer code behavior, e.g.
asdf uses snake_case global constants in a number of places that could be replaced with screaming snake_case.
Unfortunately there isn't really a good way to deprecate a global variable. Things like
@deprecatedorDeprecationWarningonly work with a function or class.The only way I'm aware of to do it is to create a custom module-level
__getattr__that can then raise aDeprecationWarningwhen the symbol is imported, but even that only works at runtime and doesn't have the nice in-IDE warnings that@deprecateddoes.I guess the other option would be to rename the variable, add the old name as an alias pointing to the new name, transition the internal code to the new name, and then just never remove/deprecate the old variable name, e.g.
The maintenance overhead of keeping the old name is pretty minimal.
Instances
Here is where I will track instances of this I've found to be fixed later:
versioning.py-supported_versionsanddefault_version