Skip to content
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

use `type=` to register enum options #7304

Merged
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

remove copious verbiage about comparing to None and add note on __eq_…

…_ contract
  • Loading branch information...
cosmicexplorer committed Mar 3, 2019
commit 7fa4c60530c8b546a3af91178098779f8ad19e29
@@ -290,16 +290,11 @@ def __new__(cls, value):
return cls._singletons[value]

# TODO: figure out if this will always trigger on primitives like strings, and what situations
# won't call this __eq__ (and therefore won't raise like we want).
# won't call this __eq__ (and therefore won't raise like we want). Also look into whether there
# is a way to return something more conventional like `NotImplemented` here that maintains the
# extra caution we're looking for.
def __eq__(self, other):
"""Redefine equality to avoid accidentally comparing against a non-enum."""
# This __eq__ implementation raises on anything that's not an instance of this enum class to
# avoid accidental comparisons, e.g. a string not being wrapped in an enum
# instance. Currently, options parsing will use == to check whether an option's value has
# changed when recording where the option's value was set (in pants.ini, the command line, the
# environment). If the option isn't set and it falls back to the default, then there will be a
# comparison against None. Comparing an enum to None is not clearly an error, so we just
# return False here.
if other is None:
return False
if type(self) != type(other):
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.