Consider this code
import argparse
class MyArgumentParser(argparse.ArgumentParser):
def parse_args(self, args=None, namespace=None):
return super().parse_args(args, namespace)ErrorThis command ProblemI believe this is the cause of I am not sure what is wrong here: |
Replies: 2 comments 3 replies
|
This isn't a bug in pyright, nor is it a bug in typeshed. Starting in pyright 1.1.339, the If you would like your code to be correct from a type checking perspective, you need to override the base class with a method signature that is compatible with the base class. |
|
I just ran into this problem as well. Having the an error with @overload
def parse_known_args(self, args: Sequence[str] | None = None, namespace: None = None) -> tuple[Namespace, list[str]]: ...
@overload
def parse_known_args(self, args: Sequence[str] | None, namespace: _N) -> tuple[_N, list[str]]: ...
@overload
def parse_known_args(self, *, namespace: _N) -> tuple[_N, list[str]]: ... |
Here's a signature for the implementation that's compatible with your overloads.
The overload signatures are used for evaluating calls to the function, and the implementation signature is used for type checking the implementation itself. If the implementation signature is not a "superset" of all of the overload signatures, then there's something wrong with one of the two.