Issue #21481: Teach argparse equality tests to return NotImplemented when comparing to unknown types.

This commit is contained in:
Raymond Hettinger 2014-05-26 00:43:27 -07:00
parent dd5e53a086
commit dea46ec965
3 changed files with 13 additions and 0 deletions

View file

@ -1198,9 +1198,13 @@ class Namespace(_AttributeHolder):
setattr(self, name, kwargs[name])
def __eq__(self, other):
if not isinstance(other, Namespace):
return NotImplemented
return vars(self) == vars(other)
def __ne__(self, other):
if not isinstance(other, Namespace):
return NotImplemented
return not (self == other)
def __contains__(self, key):