Issue #21481: Teach argparse equality tests to return NotImplemented when comparing to unknown types.
diff --git a/Lib/argparse.py b/Lib/argparse.py
index a4009d0..b5bb19a 100644
--- a/Lib/argparse.py
+++ b/Lib/argparse.py
@@ -1157,9 +1157,13 @@
__hash__ = None
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):