[issue37150] Do not allow to pass FileType class object instead of instance in add_argument

Demid report at bugs.python.org
Tue Jun 4 19:50:25 EDT 2019


Demid <grrrr at protonmail.com> added the comment:

If you will run `python test.py hello.txt, where test.py is:

import argparse

parser = argparse.ArgumentParser()
parser.add_argument('echo', type=argparse.FileType)
args = parser.parse_args()
print(args.echo)

You will receive:
FileType('hello.txt')

I think that can be confusing for someone who will forget to invoke FileType constructor.

‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
On Tuesday, June 4, 2019 10:27 PM, Michele Angrisano <report at bugs.python.org> wrote:

>
>
> Michele Angrisanomichele.angrisano at gmail.com added the comment:
>
> Reading the examples in the doc, it's clear the behavior when FileType takes an argument. What's the behavior of FileType when is called without any argument?
>
> -----------------------------------------------------------------------------------------------------------------------------------------------------------------
>
> nosy: +mangrisano
>
> Python tracker report at bugs.python.org
> https://bugs.python.org/issue37150

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue37150>
_______________________________________


More information about the Python-bugs-list mailing list