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

2019-06-07 Thread Andrew Svetlov


Change by Andrew Svetlov :


--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed
versions:  -Python 2.7, Python 3.7

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2019-06-07 Thread miss-islington


miss-islington  added the comment:


New changeset 606ac581e2451c420117c55632f0fe13d4cec2cd by Miss Islington (bot) 
in branch '3.8':
bpo-37150: Throw ValueError if FileType class object was passed in add_argument 
(GH-13805)
https://github.com/python/cpython/commit/606ac581e2451c420117c55632f0fe13d4cec2cd


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2019-06-07 Thread miss-islington


Change by miss-islington :


--
pull_requests: +13776
pull_request: https://github.com/python/cpython/pull/13901

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2019-06-07 Thread miss-islington


miss-islington  added the comment:


New changeset 03d5831a2d62c68654ec223168e574cd546efbf6 by Miss Islington (bot) 
(zygocephalus) in branch 'master':
bpo-37150: Throw ValueError if FileType class object was passed in add_argument 
(GH-13805)
https://github.com/python/cpython/commit/03d5831a2d62c68654ec223168e574cd546efbf6


--
nosy: +miss-islington

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2019-06-07 Thread Michele Angrisano


Change by Michele Angrisano :


--
nosy: +bethard

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2019-06-05 Thread Demid


Demid  added the comment:

What if I will add mode check in FileType.__init__?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2019-06-04 Thread Josh Rosenberg


Josh Rosenberg  added the comment:

Ah, right. It doesn't actually validate the mode string (it just stores it for 
when open is called, assuming open will validate it). So yeah, it silently 
accepts any string, not just valid mode strings. Not a contractual guarantee or 
anything, just how FileType.__init__ is implemented.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2019-06-04 Thread Demid

Demid  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  
wrote:

>
>
> Michele angrisanomichele.angris...@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 rep...@bugs.python.org
> https://bugs.python.org/issue37150

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2019-06-04 Thread Michele Angrisano


Michele Angrisano  added the comment:

Yes, I meant that. Thanks! :)

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2019-06-04 Thread Josh Rosenberg


Josh Rosenberg  added the comment:

The docs specify what argparse.FileType() does via the default parameters: 
https://docs.python.org/3/library/argparse.html#argparse.FileType

If you mean what does it do when you fail to call it at all (passing 
type=argparse.FileType), the answer is the same as any other class: It tries to 
construct a FileType using the user provided argument as the sole positional 
argument. So if the user passes a valid mode string, it works, and returns a 
FileType object with that mode string, otherwise it barfs and dumps an error 
message for passing an invalid argument for FileType.

--
nosy: +josh.r

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2019-06-04 Thread Michele Angrisano


Michele Angrisano  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 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2019-06-04 Thread paul j3


paul j3  added the comment:

I don't see an easy way around this.  FileType is a class, and thus is a 
callable.  add_argument checks that the 'type' parameter is a callable (or a 
string in the registry).  Otherwise it gives the programmer a lot of freedom 
regarding this parameter.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2019-06-04 Thread Karthikeyan Singaravelan


Change by Karthikeyan Singaravelan :


--
nosy: +paul.j3

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2019-06-04 Thread SilentGhost


Change by SilentGhost :


--
versions:  -Python 3.5, Python 3.6

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2019-06-04 Thread Demid


Change by Demid :


--
keywords: +patch
pull_requests: +13690
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/13805

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2019-06-04 Thread Demid


New submission from Demid :

There is a possibility that someone (like me) accidentally will omit 
parentheses with FileType arguments after FileType, and parser will contain 
wrong file until someone will try to use it. 

Example:
parser = argparse.ArgumentParser()
parser.add_argument('-x', type=argparse.FileType)

--
components: Library (Lib)
messages: 344568
nosy: zygocephalus
priority: normal
severity: normal
status: open
title: Do not allow to pass FileType class object instead of instance in 
add_argument
type: enhancement
versions: Python 2.7, Python 3.5, Python 3.6, Python 3.7, Python 3.8, Python 3.9

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com