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
Type inference override #765
Comments
There's no type inference applied when evaluating the type of the expression The problem here is that you are not specifying a namespace argument to args = parser.parse_args(namespace=Args()) |
I see, thank you. That does set the tooltip properly. Maybe this is beyond the scope, but do you know if it's possible to do this with multiple subparsers (e.g. |
Sorry, but the only thing I know about |
I appreciate the help anyway! I guess it's not possible to override the type that Pylance thinks a variable is, then. |
I'm not sure if this is a bug or a feature request, but in order to support auto-completion for argparse (see #628) in other language servers (the default vscode one, Microsoft I think?) I like to create a marker class defining the acceptable properties and then manually annotate the type signature of the
parse_args
method with the class, so it's used when auto-completing. Pylance, however, ignores my manual annotation and continues to assume the type is the return type fromparse_args
(which isNamespace
).Note: I don't expect Pylance to special-case code for argparse. I simply want it to use my
Args
class as the type for all inference decisions, even if I make a mistake and myArgs
class gets out of sync with how I've actually configured my argparse parser.This is a minimal reproduction:
The inferred type is
Namespace
, but it would be nice if it saidArgs
(however, the default language server also showsNamespace
despite the annotation, so this is less important than auto-complete support):This is the auto-complete output from the Pylance language server. There is no suggestion for
command
.This is the auto-complete output from the default language server, which includes
command
as a suggestion:The text was updated successfully, but these errors were encountered: