# Buggy code
def enum(*args):
    """A datatype which can take on a finite set of values. This method is experimental and unstable.

    Any enum subclass can be constructed with its create() classmethod. This method will use the first
    element of `all_values` as the default value, but enum classes can override this behavior by
    setting `default_value` in the class body.

    NB: Relying on the `field_name` directly is discouraged in favor of using
    resolve_for_enum_variant() in Python code. The `field_name` argument is exposed to make enum
    instances more readable when printed, and to allow code in another language using an FFI to
    reliably extract the value from an enum instance.

    :param string field_name: A string used as the field for the datatype. This positional argument is
                              optional, and defaults to 'value'. Note that `enum()` does not yet
                              support type checking as with `datatype()`.
    :param Iterable all_values: A nonempty iterable of objects representing all possible values for
                                the enum.  This argument must be a finite, non-empty iterable with
                                unique values.
    :raises: :class:`ValueError`
    """
    if len(args) == 1:
        field_name = "value"
        (all_values,) = args
    elif len(args) == 2:
        field_name, all_values = args
    else:
        raise ValueError("enum() accepts only 1 or 2 args! args = {!r}".format(args))

    # This call to list() will eagerly evaluate any `all_values` which would otherwise be lazy, such
    # as a generator.
    all_values_realized = list(all_values)
    # `OrderedSet` maintains the order of the input iterable, but is faster to check membership.
    allowed_values_set = OrderedSet(all_values_realized)

    if len(allowed_values_set) == 0:
        raise ValueError("all_values must be a non-empty iterable!")
    elif len(allowed_values_set) < len(all_values_realized):
        raise ValueError(
            "When converting all_values ({}) to a set, at least one duplicate "
            "was detected. The unique elements of all_values were: {}.".format(
                all_values_realized, list(allowed_values_set)
            )
        )

    class ChoiceDatatype(datatype([field_name])):
        default_value = next(iter(allowed_values_set))

        # Overriden from datatype() so providing an invalid variant is catchable as a TypeCheckError,
        # but more specific.
        type_check_error_type = EnumVariantSelectionError

        @memoized_classproperty
        def _singletons(cls):
            """Generate memoized instances of this enum wrapping each of this enum's allowed values.

            NB: The implementation of enum() should use this property as the source of truth for allowed
            values and enum instances from those values.
            """
            return OrderedDict(
                (value, cls._make_singleton(value)) for value in allowed_values_set
            )

        @classmethod
        def _make_singleton(cls, value):
            """
            We convert uses of the constructor to call create(), so we then need to go around __new__ to
            bootstrap singleton creation from datatype()'s __new__.
            """
            return super(ChoiceDatatype, cls).__new__(cls, value)

        @classproperty
        def _allowed_values(cls):
            """The values provided to the enum() type constructor, for use in error messages."""
            return list(cls._singletons.keys())

        def __new__(cls, value):
            """Forward `value` to the .create() factory method.

            The .create() factory method is preferred, but forwarding the constructor like this allows us
            to use the generated enum type both as a type to check against with isinstance() as well as a
            function to create instances with. This makes it easy to use as a pants option type.
            """
            return cls.create(value)

        @classmethod
        def create(cls, *args, **kwargs):
            """Create an instance of this enum, using the default value if specified.

            :param value: Use this as the enum value. If `value` is an instance of this class, return it,
                          otherwise it is checked against the enum's allowed values. This positional
                          argument is optional, and if not specified, `cls.default_value` is used.
            :param bool none_is_default: If this is True, a None `value` is converted into
                                         `cls.default_value` before being checked against the enum's
                                         allowed values.
            """
            none_is_default = kwargs.pop("none_is_default", False)
            if kwargs:
                raise ValueError(
                    "unrecognized keyword arguments for {}.create(): {!r}".format(
                        cls.__name__, kwargs
                    )
                )

            if len(args) == 0:
                value = cls.default_value
            elif len(args) == 1:
                value = args[0]
                if none_is_default and value is None:
                    value = cls.default_value
            else:
                raise ValueError(
                    "{}.create() accepts 0 or 1 positional args! *args = {!r}".format(
                        cls.__name__, args
                    )
                )

            # If we get an instance of this enum class, just return it. This means you can call .create()
            # on an allowed value for the enum, or an existing instance of the enum.
            if isinstance(value, cls):
                return value

            if value not in cls._singletons:
                raise cls.make_type_error(
                    "Value {!r} for '{}' must be one of: {!r}.".format(
                        value, field_name, cls._allowed_values
                    )
                )
            return cls._singletons[value]

        def resolve_for_enum_variant(self, mapping):
            """Return the object in `mapping` with the key corresponding to the enum value.

            `mapping` is a dict mapping enum variant value -> arbitrary object. All variant values must be
            provided.

            NB: The objects in `mapping` should be made into lambdas if lazy execution is desired, as this
            will "evaluate" all of the values in `mapping`.
            """
            keys = frozenset(mapping.keys())
            if keys != frozenset(self._allowed_values):
                raise self.make_type_error(
                    "pattern matching must have exactly the keys {} (was: {})".format(
                        self._allowed_values, list(keys)
                    )
                )
            match_for_variant = mapping[getattr(self, field_name)]
            return match_for_variant

        @classmethod
        def iterate_enum_variants(cls):
            """Iterate over all instances of this enum, in the declared order.

            NB: This method is exposed for testing enum variants easily. resolve_for_enum_variant() should
            be used for performing conditional logic based on an enum instance's value.
            """
            # TODO(#7232): use this method to register attributes on the generated type object for each of
            # the singletons!
            return cls._singletons.values()

    return ChoiceDatatype


# Traceback (AssertionError)
==================== FAILURES ====================
 CTypesIntegrationTest.test_ctypes_third_party_integration 

args = (<pants_test.backend.python.tasks.native.test_ctypes_integration.CTypesIntegrationTest testMethod=test_ctypes_third_party_integration>,)
kwargs = {}
variant = ToolchainVariant(value=u'gnu')

    @wraps(func)
    def wrapper(*args, **kwargs):
      for variant in ToolchainVariant.iterate_enum_variants():
>       func(*args, toolchain_variant=variant, **kwargs)

.pants.d/pyprep/sources/68db53b799a649f3f92cbd3d3e740d9a1a47be07/pants_test/backend/python/tasks/native/test_ctypes_integration.py:32: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
.pants.d/pyprep/sources/68db53b799a649f3f92cbd3d3e740d9a1a47be07/pants_test/backend/python/tasks/native/test_ctypes_integration.py:195: in test_ctypes_third_party_integration
    self.assert_success(pants_run)
.pants.d/pyprep/sources/68db53b799a649f3f92cbd3d3e740d9a1a47be07/pants_test/pants_run_integration_test.py:452: in assert_success
    self.assert_result(pants_run, self.PANTS_SUCCESS_CODE, expected=True, msg=msg)
.pants.d/pyprep/sources/68db53b799a649f3f92cbd3d3e740d9a1a47be07/pants_test/pants_run_integration_test.py:473: in assert_result
    assertion(value, pants_run.returncode, error_msg)
E   AssertionError: /Users/travis/build/pantsbuild/pants/pants --no-pantsrc --pants-workdir=/Users/travis/build/pantsbuild/pants/.pants.d/tmp/tmp1ZloAV.pants.d --kill-nailguns --print-exception-stacktrace=True --pants-config-files=/Users/travis/build/pantsbuild/pants/.pants.d/tmp/tmp1ZloAV.pants.d/pants.ini -q run testprojects/src/python/python_distribution/ctypes_with_third_party:bin_with_third_party
E   returncode: 1
E   stdout:
E   	
E   	FAILURE: /usr/bin/python /Users/travis/build/pantsbuild/pants/.pants.d/tmp/tmp1ZloAV.pants.d/run/py/CPython-2.7.10/a8a8db2fdd4fae99b02f6010a93d6f6dc4f9f3dc ... exited non-zero (1)
E   	
E   stderr:
E   	Traceback (most recent call last):
E   	  File "/Users/travis/build/pantsbuild/pants/.pants.d/tmp/tmp1ZloAV.pants.d/run/py/CPython-2.7.10/a8a8db2fdd4fae99b02f6010a93d6f6dc4f9f3dc/.bootstrap/_pex/pex.py", line 349, in execute
E   	    exit_code = self._wrap_coverage(self._wrap_profiling, self._execute)
E   	  File "/Users/travis/build/pantsbuild/pants/.pants.d/tmp/tmp1ZloAV.pants.d/run/py/CPython-2.7.10/a8a8db2fdd4fae99b02f6010a93d6f6dc4f9f3dc/.bootstrap/_pex/pex.py", line 281, in _wrap_coverage
E   	    return runner(*args)
E   	  File "/Users/travis/build/pantsbuild/pants/.pants.d/tmp/tmp1ZloAV.pants.d/run/py/CPython-2.7.10/a8a8db2fdd4fae99b02f6010a93d6f6dc4f9f3dc/.bootstrap/_pex/pex.py", line 312, in _wrap_profiling
E   	    return runner(*args)
E   	  File "/Users/travis/build/pantsbuild/pants/.pants.d/tmp/tmp1ZloAV.pants.d/run/py/CPython-2.7.10/a8a8db2fdd4fae99b02f6010a93d6f6dc4f9f3dc/.bootstrap/_pex/pex.py", line 394, in _execute
E   	    return self.execute_entry(self._pex_info.entry_point)
E   	  File "/Users/travis/build/pantsbuild/pants/.pants.d/tmp/tmp1ZloAV.pants.d/run/py/CPython-2.7.10/a8a8db2fdd4fae99b02f6010a93d6f6dc4f9f3dc/.bootstrap/_pex/pex.py", line 506, in execute_entry
E   	    return runner(entry_point)
E   	  File "/Users/travis/build/pantsbuild/pants/.pants.d/tmp/tmp1ZloAV.pants.d/run/py/CPython-2.7.10/a8a8db2fdd4fae99b02f6010a93d6f6dc4f9f3dc/.bootstrap/_pex/pex.py", line 513, in execute_module
E   	    runpy.run_module(module_name, run_name='__main__')
E   	  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 180, in run_module
E   	    fname, loader, pkg_name)
E   	  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 72, in _run_code
E   	    exec code in run_globals
E   	  File "/Users/travis/build/pantsbuild/pants/.pants.d/tmp/tmp1ZloAV.pants.d/pyprep/sources/46bc27ffbe03ecfe648c4d677289275aa6a6a93c-DefaultFingerprintStrategy_1b8903baa709/python_distribution/ctypes_with_third_party/main.py", line 7, in <module>
E   	    from ctypes_python_pkg.ctypes_wrapper import f
E   	  File "/Users/travis/build/pantsbuild/pants/.pants.d/tmp/tmp1ZloAV.pants.d/pyprep/requirements/CPython-2.7.10/dbfa0d2bb6877c576abca571691b6e7c8432a15a-DefaultFingerprintStrategy_25eb7243d755/.deps/ctypes_third_party_test-0.0.1+20865c6b4968b7f61c37fdc3ed80306ee2ca4a3e.defaultfingerprintstrategy.174c3658bd6c.8f03fa43ba4e-py2-none-macosx_10_13_x86_64.whl/ctypes_python_pkg/ctypes_wrapper.py", line 20, in <module>
E   	    asdf_cpp_lib = ctypes.CDLL(asdf_cpp_lib_path)
E   	  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ctypes/__init__.py", line 365, in __init__
E   	    self._handle = _dlopen(self._name, mode)
E   	OSError: dlopen(/Users/travis/build/pantsbuild/pants/.pants.d/tmp/tmp1ZloAV.pants.d/pyprep/requirements/CPython-2.7.10/dbfa0d2bb6877c576abca571691b6e7c8432a15a-DefaultFingerprintStrategy_25eb7243d755/.deps/ctypes_third_party_test-0.0.1+20865c6b4968b7f61c37fdc3ed80306ee2ca4a3e.defaultfingerprintstrategy.174c3658bd6c.8f03fa43ba4e-py2-none-macosx_10_13_x86_64.whl/libasdf-cpp_ctypes-with-third-party.so, 6): Library not loaded: /Users/stuhood/src/pantsbuild-binaries/build-support/bin/gcc/mac/10.13/7.3.0/gcc-7.3.0-osx/gcc-install/lib/libstdc++.6.dylib
E   	  Referenced from: /Users/travis/build/pantsbuild/pants/.pants.d/tmp/tmp1ZloAV.pants.d/pyprep/requirements/CPython-2.7.10/dbfa0d2bb6877c576abca571691b6e7c8432a15a-DefaultFingerprintStrategy_25eb7243d755/.deps/ctypes_third_party_test-0.0.1+20865c6b4968b7f61c37fdc3ed80306ee2ca4a3e.defaultfingerprintstrategy.174c3658bd6c.8f03fa43ba4e-py2-none-macosx_10_13_x86_64.whl/libasdf-cpp_ctypes-with-third-party.so
E   	  Reason: image not found
E   	
E   	FAILURE
-------------- Captured stdout call --------------
logs/exceptions.4006.log +++ 
logs/exceptions.4006.log --- 
logs/exceptions.log +++ 
logs/exceptions.log --- 
 CTypesIntegrationTest.test_native_compiler_option_sets_integration 

args = (<pants_test.backend.python.tasks.native.test_ctypes_integration.CTypesIntegrationTest testMethod=test_native_compiler_option_sets_integration>,)
kwargs = {}
variant = ToolchainVariant(value=u'gnu')

    @wraps(func)
    def wrapper(*args, **kwargs):
      for variant in ToolchainVariant.iterate_enum_variants():
>       func(*args, toolchain_variant=variant, **kwargs)

.pants.d/pyprep/sources/68db53b799a649f3f92cbd3d3e740d9a1a47be07/pants_test/backend/python/tasks/native/test_ctypes_integration.py:32: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
.pants.d/pyprep/sources/68db53b799a649f3f92cbd3d3e740d9a1a47be07/pants_test/backend/python/tasks/native/test_ctypes_integration.py:246: in test_native_compiler_option_sets_integration
    self.assert_success(pants_run)
.pants.d/pyprep/sources/68db53b799a649f3f92cbd3d3e740d9a1a47be07/pants_test/pants_run_integration_test.py:452: in assert_success
    self.assert_result(pants_run, self.PANTS_SUCCESS_CODE, expected=True, msg=msg)
.pants.d/pyprep/sources/68db53b799a649f3f92cbd3d3e740d9a1a47be07/pants_test/pants_run_integration_test.py:473: in assert_result
    assertion(value, pants_run.returncode, error_msg)
E   AssertionError: /Users/travis/build/pantsbuild/pants/pants --no-pantsrc --pants-workdir=/Users/travis/build/pantsbuild/pants/.pants.d/tmp/tmp8qW7hO.pants.d --kill-nailguns --print-exception-stacktrace=True --pants-config-files=/Users/travis/build/pantsbuild/pants/.pants.d/tmp/tmp8qW7hO.pants.d/pants.ini run testprojects/src/python/python_distribution/ctypes_with_extra_compiler_flags:bin
E   returncode: 1
E   stdout:
E   	
E   	16:40:21 00:00 [main]
E   	               (To run a reporting server: ./pants server)
E   	16:40:22 00:01   [setup]
E   	16:40:22 00:01     [parse]
E   	               Executing tasks in goals: bootstrap -> imports -> unpack-jars -> unpack-wheels -> deferred-sources -> native-compile -> link -> jvm-platform-validate -> gen -> pyprep -> resolve -> resources -> compile -> binary -> run
E   	16:40:23 00:02   [bootstrap]
E   	16:40:23 00:02     [substitute-aliased-targets]
E   	16:40:23 00:02     [jar-dependency-management]
E   	16:40:23 00:02     [bootstrap-jvm-tools]
E   	16:40:23 00:02     [provide-tools-jar]
E   	16:40:24 00:03   [imports]
E   	16:40:24 00:03     [ivy-imports]
E   	16:40:24 00:03   [unpack-jars]
E   	16:40:24 00:03     [unpack-jars]
E   	16:40:24 00:03   [unpack-wheels]
E   	16:40:24 00:03     [unpack-wheels]
E   	16:40:24 00:03   [deferred-sources]
E   	16:40:24 00:03     [deferred-sources]
E   	16:40:24 00:03   [native-compile]
E   	16:40:24 00:03     [conan-prep]
E   	16:40:24 00:03       [create-conan-pex]
E   	16:40:32 00:11     [conan-fetch]
E   	16:40:32 00:11     [c-for-ctypes]
E   	16:40:32 00:11     [cpp-for-ctypes]
E   	                   Invalidated 1 target.
E   	                   selected compiler exe name: 'g++'
E   	16:40:32 00:11       [cpp-compile]
E   	                     
E   	16:40:33 00:12   [link]
E   	16:40:33 00:12     [shared-libraries]
E   	                   Invalidated 1 target.
E   	                   selected linker exe name: 'g++'
E   	16:40:33 00:12       [link-shared-libraries]
E   	16:40:33 00:12   [jvm-platform-validate]
E   	16:40:33 00:12     [jvm-platform-validate]
E   	16:40:33 00:12   [gen]
E   	16:40:33 00:12     [antlr-java]
E   	16:40:33 00:12     [antlr-py]
E   	16:40:33 00:12     [jaxb]
E   	16:40:33 00:12     [protoc]
E   	16:40:33 00:12     [ragel]
E   	16:40:33 00:12     [thrift-java]
E   	16:40:33 00:12     [thrift-py]
E   	16:40:33 00:12     [grpcio-prep]
E   	16:40:33 00:12     [grpcio-run]
E   	16:40:33 00:12     [wire]
E   	16:40:33 00:12     [avro-java]
E   	16:40:33 00:12     [go-thrift]
E   	16:40:33 00:12     [go-protobuf]
E   	16:40:33 00:12     [jax-ws]
E   	16:40:33 00:12     [scrooge]
E   	16:40:33 00:12     [thrifty]
E   	16:40:33 00:12   [pyprep]
E   	16:40:33 00:12     [interpreter]
E   	16:40:33 00:12     [build-local-dists]
E   	                   Invalidated 1 target.
E   	16:40:35 00:14       [setup.py]
E   	16:40:35 00:14     [requirements]
E   	                   Invalidated 1 target.
E   	16:40:36 00:15     [sources]
E   	                   Invalidated 1 target.
E   	16:40:36 00:15   [resolve]
E   	16:40:36 00:15     [ivy]
E   	16:40:36 00:15     [coursier]
E   	16:40:36 00:15     [go]
E   	16:40:36 00:15     [scala-js-compile]
E   	16:40:36 00:15     [scala-js-link]
E   	16:40:37 00:16     [node]
E   	16:40:37 00:16   [resources]
E   	16:40:37 00:16     [prepare]
E   	16:40:37 00:16     [services]
E   	16:40:37 00:16   [compile]
E   	16:40:37 00:16     [node]
E   	16:40:37 00:16     [compile-jvm-prep-command]
E   	16:40:37 00:16       [jvm_prep_command]
E   	16:40:37 00:16     [compile-prep-command]
E   	16:40:37 00:16     [compile]
E   	16:40:37 00:16     [rsc]
E   	16:40:37 00:16     [zinc]
E   	16:40:37 00:16     [javac]
E   	16:40:37 00:16     [cpp]
E   	16:40:37 00:16     [errorprone]
E   	16:40:37 00:16     [findbugs]
E   	16:40:37 00:16     [go]
E   	16:40:37 00:16   [binary]
E   	16:40:37 00:16     [binary-jvm-prep-command]
E   	16:40:37 00:16       [jvm_prep_command]
E   	16:40:37 00:16     [binary-prep-command]
E   	16:40:37 00:16     [py]
E   	                   Invalidated 1 target.
E   	                   created pex dist/bin.pex
E   	16:40:38 00:17     [py-wheels]
E   	                   created wheel dist/ctypes_test-0.0.1+74173b5ce60ddd85088b1fed70c8b071f2679604.defaultfingerprintstrategy.12652e89be0f.8f03fa43ba4e-py2-none-macosx_10_13_x86_64.whl
E   	16:40:38 00:17     [jvm]
E   	16:40:38 00:17     [dup]
E   	16:40:38 00:17     [cpplib]
E   	16:40:38 00:17       [cpp-library]
E   	16:40:38 00:17     [cpp]
E   	16:40:38 00:17       [cpp-binary]
E   	16:40:38 00:17     [go]
E   	16:40:38 00:17   [run]
E   	16:40:38 00:17     [py]
E   	                   Invalidated 3 targets.
E   	16:40:39 00:18       [run]
E   	
E   	FAILURE: /usr/bin/python /Users/travis/build/pantsbuild/pants/.pants.d/tmp/tmp8qW7hO.pants.d/run/py/CPython-2.7.10/3784d4150334a9a89ddceb31bdb13969e94f73b2 ... exited non-zero (1)
E   	
E   	
E   	               Waiting for background workers to finish.
E   	16:40:39 00:18   [complete]
E   	               FAILURE
E   stderr:
E   	Traceback (most recent call last):
E   	  File "/Users/travis/build/pantsbuild/pants/.pants.d/tmp/tmp8qW7hO.pants.d/run/py/CPython-2.7.10/3784d4150334a9a89ddceb31bdb13969e94f73b2/.bootstrap/_pex/pex.py", line 349, in execute
E   	    exit_code = self._wrap_coverage(self._wrap_profiling, self._execute)
E   	  File "/Users/travis/build/pantsbuild/pants/.pants.d/tmp/tmp8qW7hO.pants.d/run/py/CPython-2.7.10/3784d4150334a9a89ddceb31bdb13969e94f73b2/.bootstrap/_pex/pex.py", line 281, in _wrap_coverage
E   	    return runner(*args)
E   	  File "/Users/travis/build/pantsbuild/pants/.pants.d/tmp/tmp8qW7hO.pants.d/run/py/CPython-2.7.10/3784d4150334a9a89ddceb31bdb13969e94f73b2/.bootstrap/_pex/pex.py", line 312, in _wrap_profiling
E   	    return runner(*args)
E   	  File "/Users/travis/build/pantsbuild/pants/.pants.d/tmp/tmp8qW7hO.pants.d/run/py/CPython-2.7.10/3784d4150334a9a89ddceb31bdb13969e94f73b2/.bootstrap/_pex/pex.py", line 394, in _execute
E   	    return self.execute_entry(self._pex_info.entry_point)
E   	  File "/Users/travis/build/pantsbuild/pants/.pants.d/tmp/tmp8qW7hO.pants.d/run/py/CPython-2.7.10/3784d4150334a9a89ddceb31bdb13969e94f73b2/.bootstrap/_pex/pex.py", line 506, in execute_entry
E   	    return runner(entry_point)
E   	  File "/Users/travis/build/pantsbuild/pants/.pants.d/tmp/tmp8qW7hO.pants.d/run/py/CPython-2.7.10/3784d4150334a9a89ddceb31bdb13969e94f73b2/.bootstrap/_pex/pex.py", line 513, in execute_module
E   	    runpy.run_module(module_name, run_name='__main__')
E   	  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 180, in run_module
E   	    fname, loader, pkg_name)
E   	  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 72, in _run_code
E   	    exec code in run_globals
E   	  File "/Users/travis/build/pantsbuild/pants/.pants.d/tmp/tmp8qW7hO.pants.d/pyprep/sources/be29db057705cafb8edc0e69942013e74ccffbe3-DefaultFingerprintStrategy_1b8903baa709/python_distribution/ctypes_with_extra_compiler_flags/main.py", line 7, in <module>
E   	    from ctypes_python_pkg.ctypes_wrapper import f
E   	  File "/Users/travis/build/pantsbuild/pants/.pants.d/tmp/tmp8qW7hO.pants.d/pyprep/requirements/CPython-2.7.10/2122a483545750a790ffdd2c65a8039affd3f167-DefaultFingerprintStrategy_25eb7243d755/.deps/ctypes_test-0.0.1+74173b5ce60ddd85088b1fed70c8b071f2679604.defaultfingerprintstrategy.12652e89be0f.8f03fa43ba4e-py2-none-macosx_10_13_x86_64.whl/ctypes_python_pkg/ctypes_wrapper.py", line 20, in <module>
E   	    asdf_cpp_lib = ctypes.CDLL(asdf_cpp_lib_path)
E   	  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ctypes/__init__.py", line 365, in __init__
E   	    self._handle = _dlopen(self._name, mode)
E   	OSError: dlopen(/Users/travis/build/pantsbuild/pants/.pants.d/tmp/tmp8qW7hO.pants.d/pyprep/requirements/CPython-2.7.10/2122a483545750a790ffdd2c65a8039affd3f167-DefaultFingerprintStrategy_25eb7243d755/.deps/ctypes_test-0.0.1+74173b5ce60ddd85088b1fed70c8b071f2679604.defaultfingerprintstrategy.12652e89be0f.8f03fa43ba4e-py2-none-macosx_10_13_x86_64.whl/libasdf-cpp_ctypes-with-extra-compiler-flags.so, 6): Library not loaded: /Users/stuhood/src/pantsbuild-binaries/build-support/bin/gcc/mac/10.13/7.3.0/gcc-7.3.0-osx/gcc-install/lib/libstdc++.6.dylib
E   	  Referenced from: /Users/travis/build/pantsbuild/pants/.pants.d/tmp/tmp8qW7hO.pants.d/pyprep/requirements/CPython-2.7.10/2122a483545750a790ffdd2c65a8039affd3f167-DefaultFingerprintStrategy_25eb7243d755/.deps/ctypes_test-0.0.1+74173b5ce60ddd85088b1fed70c8b071f2679604.defaultfingerprintstrategy.12652e89be0f.8f03fa43ba4e-py2-none-macosx_10_13_x86_64.whl/libasdf-cpp_ctypes-with-extra-compiler-flags.so
E   	  Reason: image not found
-------------- Captured stdout call --------------
logs/exceptions.4063.log +++ 
logs/exceptions.4063.log --- 
logs/exceptions.log +++ 
logs/exceptions.log --- 
====== 2 failed, 3 passed in 199.95 seconds ======

# Fixed code
def enum(*args):
    """A datatype which can take on a finite set of values. This method is experimental and unstable.

    Any enum subclass can be constructed with its create() classmethod. This method will use the first
    element of `all_values` as the default value, but enum classes can override this behavior by
    setting `default_value` in the class body.

    NB: Relying on the `field_name` directly is discouraged in favor of using
    resolve_for_enum_variant() in Python code. The `field_name` argument is exposed to make enum
    instances more readable when printed, and to allow code in another language using an FFI to
    reliably extract the value from an enum instance.

    :param string field_name: A string used as the field for the datatype. This positional argument is
                              optional, and defaults to 'value'. Note that `enum()` does not yet
                              support type checking as with `datatype()`.
    :param Iterable all_values: A nonempty iterable of objects representing all possible values for
                                the enum.  This argument must be a finite, non-empty iterable with
                                unique values.
    :raises: :class:`ValueError`
    """
    if len(args) == 1:
        field_name = "value"
        (all_values,) = args
    elif len(args) == 2:
        field_name, all_values = args
    else:
        raise ValueError("enum() accepts only 1 or 2 args! args = {!r}".format(args))

    # This call to list() will eagerly evaluate any `all_values` which would otherwise be lazy, such
    # as a generator.
    all_values_realized = list(all_values)
    # `OrderedSet` maintains the order of the input iterable, but is faster to check membership.
    allowed_values_set = OrderedSet(all_values_realized)

    if len(allowed_values_set) == 0:
        raise ValueError("all_values must be a non-empty iterable!")
    elif len(allowed_values_set) < len(all_values_realized):
        raise ValueError(
            "When converting all_values ({}) to a set, at least one duplicate "
            "was detected. The unique elements of all_values were: {}.".format(
                all_values_realized, list(allowed_values_set)
            )
        )

    class ChoiceDatatype(datatype([field_name])):
        default_value = next(iter(allowed_values_set))

        # Overriden from datatype() so providing an invalid variant is catchable as a TypeCheckError,
        # but more specific.
        type_check_error_type = EnumVariantSelectionError

        @memoized_classproperty
        def _singletons(cls):
            """Generate memoized instances of this enum wrapping each of this enum's allowed values.

            NB: The implementation of enum() should use this property as the source of truth for allowed
            values and enum instances from those values.
            """
            return OrderedDict(
                (value, cls._make_singleton(value)) for value in allowed_values_set
            )

        @classmethod
        def _make_singleton(cls, value):
            """
            We convert uses of the constructor to call create(), so we then need to go around __new__ to
            bootstrap singleton creation from datatype()'s __new__.
            """
            return super(ChoiceDatatype, cls).__new__(cls, value)

        @classproperty
        def _allowed_values(cls):
            """The values provided to the enum() type constructor, for use in error messages."""
            return list(cls._singletons.keys())

        def __new__(cls, value):
            """Forward `value` to the .create() factory method.

            The .create() factory method is preferred, but forwarding the constructor like this allows us
            to use the generated enum type both as a type to check against with isinstance() as well as a
            function to create instances with. This makes it easy to use as a pants option type.
            """
            return cls.create(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).
        def __eq__(self, other):
            """Redefine equality to raise to nudge people to use static pattern matching."""
            raise self.make_type_error(
                "enum equality is defined to be an error -- use .resolve_for_enum_variant() instead!"
            )

        # Redefine the canary so datatype __new__ doesn't raise.
        __eq__._eq_override_canary = None

        # NB: as noted in datatype(), __hash__ must be explicitly implemented whenever __eq__ is
        # overridden. See https://docs.python.org/3/reference/datamodel.html#object.__hash__.
        def __hash__(self):
            return super(ChoiceDatatype, self).__hash__()

        @classmethod
        def create(cls, *args, **kwargs):
            """Create an instance of this enum, using the default value if specified.

            :param value: Use this as the enum value. If `value` is an instance of this class, return it,
                          otherwise it is checked against the enum's allowed values. This positional
                          argument is optional, and if not specified, `cls.default_value` is used.
            :param bool none_is_default: If this is True, a None `value` is converted into
                                         `cls.default_value` before being checked against the enum's
                                         allowed values.
            """
            none_is_default = kwargs.pop("none_is_default", False)
            if kwargs:
                raise ValueError(
                    "unrecognized keyword arguments for {}.create(): {!r}".format(
                        cls.__name__, kwargs
                    )
                )

            if len(args) == 0:
                value = cls.default_value
            elif len(args) == 1:
                value = args[0]
                if none_is_default and value is None:
                    value = cls.default_value
            else:
                raise ValueError(
                    "{}.create() accepts 0 or 1 positional args! *args = {!r}".format(
                        cls.__name__, args
                    )
                )

            # If we get an instance of this enum class, just return it. This means you can call .create()
            # on an allowed value for the enum, or an existing instance of the enum.
            if isinstance(value, cls):
                return value

            if value not in cls._singletons:
                raise cls.make_type_error(
                    "Value {!r} for '{}' must be one of: {!r}.".format(
                        value, field_name, cls._allowed_values
                    )
                )
            return cls._singletons[value]

        def resolve_for_enum_variant(self, mapping):
            """Return the object in `mapping` with the key corresponding to the enum value.

            `mapping` is a dict mapping enum variant value -> arbitrary object. All variant values must be
            provided.

            NB: The objects in `mapping` should be made into lambdas if lazy execution is desired, as this
            will "evaluate" all of the values in `mapping`.
            """
            keys = frozenset(mapping.keys())
            if keys != frozenset(self._allowed_values):
                raise self.make_type_error(
                    "pattern matching must have exactly the keys {} (was: {})".format(
                        self._allowed_values, list(keys)
                    )
                )
            match_for_variant = mapping[getattr(self, field_name)]
            return match_for_variant

        @classmethod
        def iterate_enum_variants(cls):
            """Iterate over all instances of this enum, in the declared order.

            NB: This method is exposed for testing enum variants easily. resolve_for_enum_variant() should
            be used for performing conditional logic based on an enum instance's value.
            """
            # TODO(#7232): use this method to register attributes on the generated type object for each of
            # the singletons!
            return cls._singletons.values()

    return ChoiceDatatype