classification
Title: Argpase Namespace object methods __eq__ and __ne__ raise TypeError when comparing to None
Type: behavior Stage: needs patch
Components: Library (Lib) Versions: Python 3.4, Python 3.5, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: rhettinger Nosy List: Joe.Borg, bethard, python-dev, rhettinger
Priority: low Keywords: patch

Created on 2014-05-12 16:08 by Joe.Borg, last changed 2014-05-26 07:45 by rhettinger. This issue is now closed.

Files
File name Uploaded Description Edit
fix_argparse_eq.diff rhettinger, 2014-05-23 01:55 Return NotImplemented for non Namespace types
Messages (5)
msg218326 - (view) Author: Joe Borg (Joe.Borg) Date: 2014-05-12 16:08
See example:

>>> import argparse
>>> a = argparse.ArgumentParser()
>>> b = a.parse_args([])
>>> if b != None:
...     print "hey"
  File "<stdin>", line 2
    print "hey"
              ^
SyntaxError: invalid syntax
>>> 
>>> if b != None:           
... 	print("hey")
... 
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/cfd/software/Python/340/lib/python3.4/argparse.py", line 1202, in __ne__
    return not (self == other)
  File "/cfd/software/Python/340/lib/python3.4/argparse.py", line 1199, in __eq__
    return vars(self) == vars(other)
TypeError: vars() argument must have __dict__ attribute
msg218330 - (view) Author: Joe Borg (Joe.Borg) Date: 2014-05-12 16:11
I believe this comes from doing vars(None).  But why would this be happening if Namespace is empty.
msg218936 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2014-05-23 00:48
The equality and inequality tests need to return NotImplemented when comparing to an unknown type.
msg219140 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2014-05-26 07:40
New changeset ba84d1e9a742 by Raymond Hettinger in branch '2.7':
Issue #21481:  Teach argparse equality tests to return NotImplemented when comparing to unknown types.
http://hg.python.org/cpython/rev/ba84d1e9a742
msg219141 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2014-05-26 07:44
New changeset 510c8dc38749 by Raymond Hettinger in branch '3.4':
Issue #21481:  Teach argparse equality tests to return NotImplemented when comparing to unknown types.
http://hg.python.org/cpython/rev/510c8dc38749
History
Date User Action Args
2014-05-26 07:45:10rhettingersetstatus: open -> closed
resolution: fixed
2014-05-26 07:44:43python-devsetmessages: + msg219141
2014-05-26 07:40:36python-devsetnosy: + python-dev
messages: + msg219140
2014-05-23 01:55:51rhettingersetfiles: + fix_argparse_eq.diff
keywords: + patch
2014-05-23 00:48:35rhettingersetpriority: normal -> low

type: behavior
assignee: rhettinger
versions: - Python 3.1, Python 3.2, Python 3.3
nosy: + rhettinger, bethard

messages: + msg218936
stage: needs patch
2014-05-12 16:11:42Joe.Borgsetmessages: + msg218330
2014-05-12 16:08:22Joe.Borgcreate