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

Default arguments should be allowed to be other than NoValue #451

Open
fsargent opened this issue Mar 16, 2023 · 5 comments · May be fixed by #452
Open

Default arguments should be allowed to be other than NoValue #451

fsargent opened this issue Mar 16, 2023 · 5 comments · May be fixed by #452
Assignees
Labels
need reproducible example Example is required to reproduce the issue

Comments

@fsargent
Copy link

Argument of type "Literal['']" cannot be assigned to parameter "default" of type "NoValue" in function "str"
"Literal['']" is incompatible with "NoValue"PylancereportGeneralTypeIssues

CleanShot 2023-03-16 at 14 04 05@2x

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):

@fsargent fsargent linked a pull request Mar 16, 2023 that will close this issue
@sergeyklay
Copy link
Collaborator

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.

@sergeyklay sergeyklay self-assigned this Sep 9, 2023
@sergeyklay sergeyklay added the need reproducible example Example is required to reproduce the issue label Sep 9, 2023
@karlisf
Copy link

karlisf commented Sep 16, 2023

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.

@djw27
Copy link

djw27 commented Oct 17, 2023

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

@dokterbob
Copy link

Poke! ;)

image

@airtonix
Copy link

is this project dead?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need reproducible example Example is required to reproduce the issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants