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: wrong type from get_default when type is set #82917

Closed
ErikAhln mannequin opened this issue Nov 7, 2019 · 4 comments
Closed

argparse: wrong type from get_default when type is set #82917

ErikAhln mannequin opened this issue Nov 7, 2019 · 4 comments
Labels
3.7 (EOL) end of life stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@ErikAhln
Copy link
Mannequin

ErikAhln mannequin commented Nov 7, 2019

BPO 38736
Files
  • test.py
  • 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 2019-11-13.05:57:24.705>
    created_at = <Date 2019-11-07.15:40:47.721>
    labels = ['3.7', 'type-feature', 'library']
    title = 'argparse: wrong type from get_default when type is set'
    updated_at = <Date 2019-11-13.05:57:24.704>
    user = 'https://bugs.python.org/ErikAhln'

    bugs.python.org fields:

    activity = <Date 2019-11-13.05:57:24.704>
    actor = 'paul.j3'
    assignee = 'none'
    closed = True
    closed_date = <Date 2019-11-13.05:57:24.705>
    closer = 'paul.j3'
    components = ['Library (Lib)']
    creation = <Date 2019-11-07.15:40:47.721>
    creator = 'Erik Ahl\xc3\xa9n'
    dependencies = []
    files = ['48700']
    hgrepos = []
    issue_num = 38736
    keywords = []
    message_count = 4.0
    messages = ['356194', '356222', '356236', '356247']
    nosy_count = 2.0
    nosy_names = ['paul.j3', 'Erik Ahl\xc3\xa9n']
    pr_nums = []
    priority = 'normal'
    resolution = None
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue38736'
    versions = ['Python 3.7']

    @ErikAhln
    Copy link
    Mannequin Author

    ErikAhln mannequin commented Nov 7, 2019

    The type of the object returned by get_default isn't converted to the specified type supplied to add_argument. I would expect the type to be the same.

    @ErikAhln ErikAhln mannequin added 3.7 (EOL) end of life stdlib Python modules in the Lib dir type-feature A feature request or enhancement labels Nov 7, 2019
    @paulj3
    Copy link
    Mannequin

    paulj3 mannequin commented Nov 8, 2019

    get_default just returns the default attribute as it is stored in the Action. Defaults are stored as given.

    During parsing the Action's default is placed in the args namespace at the start. At the end, it checks if the value in the namespace is a string that matches the default (i.e. has been over written by user input). Only then is it passed through the type function.

    @ErikAhln
    Copy link
    Mannequin Author

    ErikAhln mannequin commented Nov 8, 2019

    So, not a bug since you can just do default = Path('file.txt')?

    @paulj3
    Copy link
    Mannequin

    paulj3 mannequin commented Nov 8, 2019

    Yes you can set the default to be any object, such as an evaluated string. If it isn't a string it won't be passed through 'type'.

    The purpose of the delayed evaluation that I described is to avoid unnecessary evaluations. The worse case would be a write filetype. You don't want to create (or over write) a default file if it never gets used.

    (I intend to close this issue).

    @paulj3 paulj3 mannequin closed this as completed Nov 13, 2019
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.7 (EOL) end of life stdlib Python modules in the Lib dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    0 participants