Skip to content

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

Closed

Description

@lkct

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.

Activity

  1. srittau commented on Jul 3, 2023

    @srittau
    Collaborator

    See discussion in #10387.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions