Skip to content

ArgumentParser.parse_args with Namespace subclass does not work anymore #10400

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

Closed
lkct opened this issue Jul 3, 2023 · 1 comment
Closed
Labels
stubs: false positive Type checkers report false errors

Comments

@lkct
Copy link

lkct commented Jul 3, 2023

Ref: microsoft/pylance-release#4569 (comment)

This is introduced in #10307. (cc @qthequartermasterman as the author)

@overload
def parse_args(self, args: Sequence[str] | None = None, namespace: Namespace | None = None) -> Namespace: ... # type: ignore[misc]
@overload
def parse_args(self, args: Sequence[str] | None, namespace: _N) -> _N: ...
@overload
def parse_args(self, *, namespace: _N) -> _N: ...

The first overload now shadows the following. E.g., ArgumentParser().parse_args(namespace=MyNamespace()) should match the third but actually matches the first, which unexpectedly returns Namespace instead of MyNamespace.

@srittau
Copy link
Collaborator

srittau commented Jul 3, 2023

See discussion in #10387.

@srittau srittau added the stubs: false positive Type checkers report false errors label Jul 3, 2023
@srittau srittau closed this as completed Jul 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stubs: false positive Type checkers report false errors
Projects
None yet
Development

No branches or pull requests

2 participants