8000 Proper __ne__ comparisons by Vlad-Shcherbina · Pull Request #6 · docopt/docopt · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Proper __ne__ comparisons #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 14, 2012
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions docopt.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,25 @@ def __repr__(self):
def __eq__(self, other):
return repr(self) == repr(other)

def __ne__(self, other):
return not self == other


class Options(object):

def __init__(self, **kw):
self.__dict__ = kw

def __eq__(self, other):
return repr(self) == repr(other)
return type(self) is type(other) and \
self.__dict__ == other.__dict__

def __ne__(self, other):
return not self == other

def __repr__(self):
return 'Options(%s)' % ',\n '.join(["%s=%s" % (kw, repr(a))
for kw, a in self.__dict__.items()])
return 'Options(%s)' % ',\n '.join("%s=%s" % (kw, repr(a))
for kw, a in self.__dict__.items())


def argument_eval(s):
Expand All @@ -77,7 +84,7 @@ def docopt(doc, args=sys.argv[1:], help=True, version=None):
docopts = [Option(parse='-' + s) for s in re.split('^ *-|\n *-', doc)[1:]]
try:
getopts, args = gnu_getopt(args,
''.join([d.short for d in docopts if d.short]),
''.join(d.short for d in docopts if d.short),
[d.long for d in docopts if d.long])
except GetoptError as e:
exit(e.msg)
Expand All @@ -89,4 +96,4 @@ def docopt(doc, args=sys.argv[1:], help=True, version=None):
exit(doc.strip())
if version is not None and k == '--version':
exit(version)
return Options(**dict([(o.name, o.value) for o in docopts])), args
return Options(**dict((o.name, o.value) for o in docopts)), args
0