django-environ
django-environ copied to clipboard
Default arguments should be allowed to be other than NoValue
Argument of type "Literal['']" cannot be assigned to parameter "default" of type "NoValue" in function "str" "Literal['']" is incompatible with "NoValue"PylancereportGeneralTypeIssues
I believe this would be fixed by changing the methods definitions to Union types.
def str(self, var, default: Union(NoValue, str) = NOTSET, multiline=False):
Hi @fsargent,
Thank you for bringing up this issue. I agree that the current type restriction for the default parameter can be limiting. To better understand the scope of this problem and to consider it for a future update, it would be really helpful if you could provide a test case that highlights the current limitations and your needs.
Your contribution in the form of a test would be invaluable for us to make the necessary adjustments.
I don't quite follow what is ment by "provide a test case", but here is the use case.
pyright 1.1.327 is producing error Argument of type "Literal[False]" cannot be assigned to parameter "default" of type "NoValue" in function "bool" for:
ENABLE_REDIRECTS = env.bool('ENABLE_REDIRECTS', default=False)
The type of parameter default is inferred from its default value which is NoValue.
For example, change the implementation of env.bool() to the following removes the error:
def bool(self, var, default: bool = NOTSET):
"""
:rtype: bool
"""
return self.get_value(var, cast=bool, default=default)
i.e. specifying the allowable type for the default parameter
Poke! ;)
is this project dead?