[issue16516] argparse types (and actions) must be hashable

2018-12-16 Thread Guido van Rossum


Guido van Rossum  added the comment:

Luna discovered that has actually been fixed in 3.8 (i.e. the master branch), 
by making {}.get hashable. So I'm closing this as fixed.

--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

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



[issue16516] argparse types (and actions) must be hashable

2018-12-11 Thread Guido van Rossum


Guido van Rossum  added the comment:

Luna and I talked a bit about this offline and we decided not to merge the PR 
(nor the original patch, which is the same). Instead Luna will add a note to 
the docs explaining the caveat.

--
nosy: +gvanrossum

___
Python tracker 

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



[issue16516] argparse types (and actions) must be hashable

2018-12-01 Thread Luna Chen


Luna Chen  added the comment:

Hi bradengroom,
I have reviewed your PR, it's just a small thing! If you could update your PR, 
it would be amazing!

Thank you!

--
nosy: +BNMetrics

___
Python tracker 

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



[issue16516] argparse types (and actions) must be hashable

2018-10-28 Thread Braden Groom


Change by Braden Groom :


--
pull_requests: +9523
stage:  -> patch review

___
Python tracker 

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



[issue16516] argparse types (and actions) must be hashable

2017-12-08 Thread Michał

Michał  added the comment:

I've got confused with the "TypeError: unhashable type: 'dict'" error creating 
a choose-from-dictionary argument in Python 3.6. I used lambda as a workaround, 
but IMO it would be great to have this patch merged.

--
nosy: +krassowski
versions: +Python 3.6

___
Python tracker 

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



[issue16516] argparse types (and actions) must be hashable

2017-10-08 Thread Mark Lawrence

Change by Mark Lawrence :


--
nosy:  -BreamoreBoy

___
Python tracker 

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



[issue16516] argparse types (and actions) must be hashable

2017-10-08 Thread Joel Nothman

Joel Nothman  added the comment:

Clearly this is not in high demand

--

___
Python tracker 

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



[issue16516] argparse types (and actions) must be hashable

2014-07-12 Thread paul j3

paul j3 added the comment:

This is a straight forward patch, modifying '_registry_get' to return 'default' 
if it gets this 'TypeError'.  'test_argparse.py' has a testcase based on 
jnothman's example.  Temporarily it includes a skipped test that would pass the 
original code.

The alternative would be to add a note to the documentation to the effect that 
the 'type' must also be hashable.  But for an edge condition like this, that 
may be more confusing than enlightening.

While 'dict(one=1, two=20).get' now works as a 'type' callable, it is not 
ideal.  If there is no match it returns None.  The alternative '.__getitem__' 
raises a KeyError.  But '_get_values' handles TypeError and ValueErrors, the 
kinds returned by 'int' and 'float'.  It also handles an ArgumentTypeError, 
giving a custom type more control over the error message.  Is it worth noting 
something about the type errors in the documentation?

I've seen users make a different error with the type parameter - 
'type=boolean', thinking this means the input should be converted to boolean.  
They are thinking of 'type' as a datatype, rather than a function that converts 
a string into something else.  I don't know of a solution other than explaining 
that 'boolean()' does not act like 'int()'.

This patch also handles the 'action' case.  However I can't think of a way 
write a Action subclass that would be unhashable.  It would have to inherit 
from both Action and dict.

--
keywords: +patch
Added file: http://bugs.python.org/file35936/patch.diff

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



[issue16516] argparse types (and actions) must be hashable

2014-07-11 Thread Mark Lawrence

Mark Lawrence added the comment:

@Paul can you take a look at this please.

--
nosy: +BreamoreBoy, paul.j3
versions: +Python 3.5

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



[issue16516] argparse types (and actions) must be hashable

2012-11-20 Thread Joel Nothman

New submission from Joel Nothman:

The argparse documentation states that type= can take any callable that takes 
a single string argument and returns the converted value. The following is an 
exception:

 import argparse
 ap = argparse.ArgumentParser()
 ap.add_argument('foo', type={}.get)
Traceback (most recent call last):
  File stdin, line 1, in module
  File /usr/lib/python3/argparse.py, line 1294, in add_argument
type_func = self._registry_get('type', action.type, action.type)
  File /usr/lib/python3/argparse.py, line 1236, in _registry_get
return self._registries[registry_name].get(value, default)
TypeError: unhashable type: 'dict'

Sadly, a method bound to an unhashable type is unhashable! (Of course, is 
trivial to use partial or lambda to make any function hashable.)

The offending line in _registry_get is intended to look up named types (or 
actions), so it perhaps only relevant for string type= and action= values, 
which could be handled explicitly instead of using dict.get(x, x) to handle 
both cases. Alternatively, the TypeError could be caught and default returned.

--
components: Library (Lib)
messages: 176040
nosy: bethard, jnothman
priority: normal
severity: normal
status: open
title: argparse types (and actions) must be hashable
type: behavior
versions: Python 2.7, Python 3.4

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16516
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com