Skip to content
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

argparse.BooleanOptionalAction accept and silently discard its the const argument #85039

Closed
remilapeyre mannequin opened this issue Jun 4, 2020 · 6 comments
Closed
Labels
3.9 only security fixes 3.10 only security fixes stdlib Python modules in the Lib dir

Comments

@remilapeyre
Copy link
Mannequin

remilapeyre mannequin commented Jun 4, 2020

BPO 40862
Nosy @rhettinger, @miss-islington, @remilapeyre
PRs
  • bpo-40862: Raise TypeError when const is given to argparse.BooleanOptionalAction #20623
  • [3.9] bpo-40862: Raise TypeError when const is given to argparse.BooleanOptionalAction (GH-20623) #20664
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2020-06-06.02:31:45.829>
    created_at = <Date 2020-06-04.11:59:48.464>
    labels = ['library', '3.9', '3.10']
    title = 'argparse.BooleanOptionalAction accept and silently discard its the const argument'
    updated_at = <Date 2020-06-07.16:22:59.941>
    user = 'https://github.com/remilapeyre'

    bugs.python.org fields:

    activity = <Date 2020-06-07.16:22:59.941>
    actor = 'paul.j3'
    assignee = 'none'
    closed = True
    closed_date = <Date 2020-06-06.02:31:45.829>
    closer = 'rhettinger'
    components = ['Library (Lib)']
    creation = <Date 2020-06-04.11:59:48.464>
    creator = 'remi.lapeyre'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 40862
    keywords = ['patch']
    message_count = 6.0
    messages = ['370703', '370772', '370776', '370777', '370792', '370811']
    nosy_count = 4.0
    nosy_names = ['rhettinger', 'paul.j3', 'miss-islington', 'remi.lapeyre']
    pr_nums = ['20623', '20664']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue40862'
    versions = ['Python 3.9', 'Python 3.10']

    @remilapeyre
    Copy link
    Mannequin Author

    remilapeyre mannequin commented Jun 4, 2020

    The action is used to store None, True or False when an argument like --foo or --no-foo is given to the cli so it has no used for this action, but it is accepted without warning:

    Python 3.10.0a0 (heads/bpo-wip:6e23a9c82b, Jun  4 2020, 13:41:35) 
    [Clang 11.0.3 (clang-1103.0.32.62)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import argparse
    >>> parser = argparse.ArgumentParser()
    >>> parser.add_argument('--foo', const='this_is_not_used', action=argparse.BooleanOptionalAction)
    BooleanOptionalAction(option_strings=['--foo', '--no-foo'], dest='foo', nargs=0, const=None, default=None, type=None, choices=None, help=None, metavar=None)
    >>> args = parser.parse_args()
    >>> args
    Namespace(foo=None)

    We could either always refuse this argument, or accepted and raise ValueError if it is different than None. The attached PR does the first.

    @remilapeyre remilapeyre mannequin added 3.9 only security fixes 3.10 only security fixes stdlib Python modules in the Lib dir labels Jun 4, 2020
    @remilapeyre remilapeyre mannequin changed the title argparse.BooleanOptionalAction accept and silently its the const argument argparse.BooleanOptionalAction accept and silently discard its the const argument Jun 4, 2020
    @remilapeyre remilapeyre mannequin changed the title argparse.BooleanOptionalAction accept and silently its the const argument argparse.BooleanOptionalAction accept and silently discard its the const argument Jun 4, 2020
    @rhettinger
    Copy link
    Contributor

    ISTM this should be addressed through documentation rather than by breaking currently deployed code that may have specified a default that already matches what the action does.

    @remilapeyre
    Copy link
    Mannequin Author

    remilapeyre mannequin commented Jun 5, 2020

    argparse.BooleanOptionalAction was introduced in Python3.9 so there is no code there should be no code that already rely on it.

    @rhettinger
    Copy link
    Contributor

    Right. Go ahead :-)

    @rhettinger
    Copy link
    Contributor

    New changeset b084d1b by Rémi Lapeyre in branch 'master':
    bpo-40862: Raise TypeError when const is given to argparse.BooleanOptionalAction (GH-20623)
    b084d1b

    @rhettinger
    Copy link
    Contributor

    New changeset d5e7348 by Miss Islington (bot) in branch '3.9':
    bpo-40862: Raise TypeError when const is given to argparse.BooleanOptionalAction (GH-20623) (GH-20664)
    d5e7348

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.9 only security fixes 3.10 only security fixes stdlib Python modules in the Lib dir
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant