-
Notifications
You must be signed in to change notification settings - Fork 767
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
Quick Fix Add "Optional" to Type Annotation
doesn't work
#1873
Comments
I debugged this, and this one's just a bug where we seemingly have forgotten to include the name of the file to edit on the quick fix. The fix is simple, but will take a little more than a line thanks to some plumbing to get a URI to the right place. |
But what about an argunent that starts life as None and stays not-None once assigned not-None object? |
I'm not sure what you mean. Can you provide a concrete example? I presume you're talking about a parameter, not an argument? (An argument is a value passed to a function, whereas a parameter is the name of an input used within a function.) |
Sorry to make you confused. Here's an example: def func(lst: list[int], start: int = 0, end: int = None):
if end is None:
end = len(lst)
# end shouldn't be None here
... In this case, we don't want |
I don't really know what the above has to do with the code action being broken; if you don't want to apply the code action, you don't have to. But, in the case above, if you type |
Ok, thank u, I understand. |
This issue has been fixed in version 2021.9.4, which we've just released. You can find the changelog here: https://github.com/microsoft/pylance-release/blob/main/CHANGELOG.md#202194-29-september-2021 |
Environment data
Expected behaviour
Quick Fix wraps function parameter type in
Optional
.Actual behaviour
This is with strict type checking.
None
is underlined with this error:When trying to apply Quick Fix nothing happens.
Code Snippet / Additional information
The text was updated successfully, but these errors were encountered: