Message382758
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 |
|
Date |
User |
Action |
Args |
2020-12-08 18:12:30 | paul.j3 | set | recipients:
+ paul.j3, rhettinger, eric.smith, xmorel, ascola |
2020-12-08 18:12:30 | paul.j3 | set | messageid: <1607451150.45.0.62206207772.issue42572@roundup.psfhosted.org> |
2020-12-08 18:12:30 | paul.j3 | link | issue42572 messages |
2020-12-08 18:12:29 | paul.j3 | create | |
|