diff --git a/src/python/pants/engine/objects.py b/src/python/pants/engine/objects.py index c5b3f5be3a0e..17b0dac1e492 100644 --- a/src/python/pants/engine/objects.py +++ b/src/python/pants/engine/objects.py @@ -8,7 +8,7 @@ from collections.abc import Iterable from typing import Generic, Iterator, TypeVar -from pants.util.meta import sentinel_attribute +from pants.util.meta import decorated_type_checkable class SerializationError(Exception): @@ -171,7 +171,7 @@ def __bool__(self) -> bool: return bool(self.dependencies) -@sentinel_attribute +@decorated_type_checkable def union(cls): """A class decorator which other classes can specify that they can resolve to with `UnionRule`. diff --git a/src/python/pants/util/meta.py b/src/python/pants/util/meta.py index 7d5f9d6eb349..c05663aa1c90 100644 --- a/src/python/pants/util/meta.py +++ b/src/python/pants/util/meta.py @@ -115,7 +115,7 @@ def staticproperty(func: Union[staticmethod, Callable]) -> ClassPropertyDescript class _ClassDecoratorWithSentinelAttribute(ABC): """Base class to wrap a class decorator which sets a "sentinel attribute". - This functionality is exposed via the `@sentinel_attribute` decorator. + This functionality is exposed via the `@decorated_type_checkable` decorator. """ @abstractmethod @@ -123,15 +123,15 @@ def __call__(self, cls: Type) -> Type: ... def define_instance_of(self, obj: Type, **kwargs) -> Type: return type(obj.__name__, (obj,), { - '_sentinel_attribute_type': type(self), + '_decorated_type_checkable_type': type(self), **kwargs }) def is_instance(self, obj: Type) -> bool: - return getattr(obj, '_sentinel_attribute_type', None) is type(self) + return getattr(obj, '_decorated_type_checkable_type', None) is type(self) -def sentinel_attribute(decorator: Callable[[Type], Type]) -> _ClassDecoratorWithSentinelAttribute: +def decorated_type_checkable(decorator: Callable[[Type], Type]) -> _ClassDecoratorWithSentinelAttribute: """Wraps a class decorator to add a "sentinel attribute" to decorated classes. A "sentinel attribute" is an attribute added to the wrapped class decorator's result with @@ -151,7 +151,7 @@ def __call__(self, cls: Type) -> Type: return WrappedFunction() -@sentinel_attribute +@decorated_type_checkable def frozen_after_init(cls: Type[_T]) -> Type[_T]: """Class decorator to freeze any modifications to the object after __init__() is done. diff --git a/tests/python/pants_test/util/test_meta.py b/tests/python/pants_test/util/test_meta.py index 9c5e831a8220..609872812c94 100644 --- a/tests/python/pants_test/util/test_meta.py +++ b/tests/python/pants_test/util/test_meta.py @@ -10,7 +10,7 @@ SingletonMetaclass, classproperty, frozen_after_init, - sentinel_attribute, + decorated_type_checkable, staticproperty, ) @@ -254,8 +254,8 @@ def f(cls): class SentinelAttributeTest(unittest.TestCase): - def test_sentinel_attribute(self): - @sentinel_attribute + def test_decorated_type_checkable(self): + @decorated_type_checkable def f(cls): return f.define_instance_of(cls) @@ -263,7 +263,7 @@ def f(cls): class C: pass - self.assertEqual(C._sentinel_attribute_type, type(f)) + self.assertEqual(C._decorated_type_checkable_type, type(f)) self.assertTrue(f.is_instance(C))