Author paul.j3
Recipients ascola, eric.smith, paul.j3, rhettinger, xmorel
Date 2020-12-08.18:12:29
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1607451150.45.0.62206207772.issue42572@roundup.psfhosted.org>
In-reply-to
Content
The pathlib.Path is new since I paid much attention to os matters (I cut my teeth on py2.5).

Off hand it looks like the user could

    import pathlib
    parser.add_argument('-p', type=pathlib.Path)

to convert a string into a Path object.

A custom type function could call this, and apply any desired methods before returning the Path object. But that should be up to the user, not the `argparse` developers.

Importing path specific modules such as pathlib (which in turn has a lot of imports) goes against the attempt to reduce the number of unnecessary imports with modules like argparse.

https://bugs.python.org/issue30152
Reduce the number of imports for argparse

After this diet argparse still imports os, and uses:

    os.path.basename

I might also note that argparse has only one custom 'type' function, the FileType factory.  Other common type functions like 'int' and 'float' are Python builtin's.  Adding a custom 'bool' (to be used instead of the builtin 'bool') has been rejected.

https://bugs.python.org/issue37564

json, yaml, and datetime types have also been rejected
https://bugs.python.org/issue35005
History
Date User Action Args
2020-12-08 18:12:30paul.j3setrecipients: + paul.j3, rhettinger, eric.smith, xmorel, ascola
2020-12-08 18:12:30paul.j3setmessageid: <1607451150.45.0.62206207772.issue42572@roundup.psfhosted.org>
2020-12-08 18:12:30paul.j3linkissue42572 messages
2020-12-08 18:12:29paul.j3create