From 1c6697fc33d6b167de61d7f80bc2688ad3a82488 Mon Sep 17 00:00:00 2001 From: Dino Viehland Date: Wed, 20 Oct 2021 17:13:03 -0700 Subject: [PATCH] Rename bind_decorate* -> resolve_decorate_* Summary: Following the `resolve_` prefix pattern this renames `bind_decorate_*` to `resolve_decorate_*` as these are used during the declaration pass. Reviewed By: carljm Differential Revision: D31580708 fbshipit-source-id: 809cb00e33 --- Lib/compiler/static/declaration_visitor.py | 2 +- Lib/compiler/static/module_table.py | 2 +- Lib/compiler/static/types.py | 40 +++++++++++----------- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/Lib/compiler/static/declaration_visitor.py b/Lib/compiler/static/declaration_visitor.py index c75b57f51ce..3cdefa21086 100644 --- a/Lib/compiler/static/declaration_visitor.py +++ b/Lib/compiler/static/declaration_visitor.py @@ -137,7 +137,7 @@ def visitClassDef(self, node: ClassDef) -> None: break with self.compiler.error_sink.error_context(self.filename, d): decorator = self.module.resolve_type(d) or DYNAMIC_TYPE - klass = decorator.bind_decorate_class(klass) + klass = decorator.resolve_decorate_class(klass) self.enter_scope(NestedScope() if klass is DYNAMIC_TYPE else klass) diff --git a/Lib/compiler/static/module_table.py b/Lib/compiler/static/module_table.py index a001579bf0c..685b490f8a7 100644 --- a/Lib/compiler/static/module_table.py +++ b/Lib/compiler/static/module_table.py @@ -175,7 +175,7 @@ def finish_decorator( res: Optional[Value] = func for decorator in reversed(node.decorator_list): decorator_type = self.resolve_decorator(decorator) or DYNAMIC_TYPE - res = decorator_type.bind_decorate_function(res, decorator) + res = decorator_type.resolve_decorate_function(res, decorator) if res is None: self.types[node] = UnknownDecoratedMethod(func) return None diff --git a/Lib/compiler/static/types.py b/Lib/compiler/static/types.py index 1f80a75859b..e0d70d768cc 100644 --- a/Lib/compiler/static/types.py +++ b/Lib/compiler/static/types.py @@ -406,12 +406,12 @@ def resolve_descr_get( ) -> Optional[Value]: return self - def bind_decorate_function( + def resolve_decorate_function( self, fn: Function | DecoratedMethod, decorator: expr ) -> Optional[Function | DecoratedMethod]: return None - def bind_decorate_class(self, klass: Class) -> Class: + def resolve_decorate_class(self, klass: Class) -> Class: return DYNAMIC_TYPE def bind_subscr( @@ -3444,7 +3444,7 @@ def emit_function( class TypingFinalDecorator(Class): - def bind_decorate_function( + def resolve_decorate_function( self, fn: Function | DecoratedMethod, decorator: expr ) -> Optional[Function | DecoratedMethod]: if isinstance(fn, DecoratedMethod): @@ -3453,19 +3453,19 @@ def bind_decorate_function( fn.is_final = True return TransparentDecoratedMethod(FUNCTION_TYPE, fn, decorator) - def bind_decorate_class(self, klass: Class) -> Class: + def resolve_decorate_class(self, klass: Class) -> Class: klass.is_final = True return klass class AllowWeakrefsDecorator(Class): - def bind_decorate_class(self, klass: Class) -> Class: + def resolve_decorate_class(self, klass: Class) -> Class: klass.allow_weakrefs = True return klass class ClassMethodDecorator(Class): - def bind_decorate_function( + def resolve_decorate_function( self, fn: Function | DecoratedMethod, decorator: expr ) -> Optional[Function | DecoratedMethod]: if fn.klass is FUNCTION_TYPE: @@ -3481,7 +3481,7 @@ def bind_decorate_function( class DynamicReturnDecorator(Class): - def bind_decorate_function( + def resolve_decorate_function( self, fn: Function | DecoratedMethod, decorator: expr ) -> Function | DecoratedMethod: if isinstance(fn, DecoratedMethod): @@ -3500,7 +3500,7 @@ def _set_dynamic_return_type(self, fn: Function) -> None: class StaticMethodDecorator(Class): - def bind_decorate_function( + def resolve_decorate_function( self, fn: Function | DecoratedMethod, decorator: expr ) -> Optional[Function | DecoratedMethod]: if fn.klass is not FUNCTION_TYPE: @@ -3517,7 +3517,7 @@ def bind_decorate_function( class InlineFunctionDecorator(Class): - def bind_decorate_function( + def resolve_decorate_function( self, fn: Function | DecoratedMethod, decorator: expr ) -> Function | DecoratedMethod: real_fn = fn.real_function if isinstance(fn, DecoratedMethod) else fn @@ -3531,61 +3531,61 @@ def bind_decorate_function( class DoNotCompileDecorator(Class): - def bind_decorate_function( + def resolve_decorate_function( self, fn: Function | DecoratedMethod, decorator: expr ) -> Optional[Function | DecoratedMethod]: real_fn = fn.real_function if isinstance(fn, DecoratedMethod) else fn real_fn.donotcompile = True return TransparentDecoratedMethod(FUNCTION_TYPE, fn, decorator) - def bind_decorate_class(self, klass: Class) -> Class: + def resolve_decorate_class(self, klass: Class) -> Class: klass.donotcompile = True return klass class PropertyDecorator(Class): - def bind_decorate_function( + def resolve_decorate_function( self, fn: Function | DecoratedMethod, decorator: expr ) -> Optional[Function | DecoratedMethod]: if fn.klass is not FUNCTION_TYPE: return None return PropertyMethod(fn, decorator) - def bind_decorate_class(self, klass: Class) -> Class: + def resolve_decorate_class(self, klass: Class) -> Class: raise TypedSyntaxError(f"Cannot decorate a class with @property") class CachedPropertyDecorator(Class): - def bind_decorate_function( + def resolve_decorate_function( self, fn: Function | DecoratedMethod, decorator: expr ) -> Optional[Function | DecoratedMethod]: if fn.klass is not FUNCTION_TYPE: return None return CachedPropertyMethod(fn, decorator) - def bind_decorate_class(self, klass: Class) -> Class: + def resolve_decorate_class(self, klass: Class) -> Class: raise TypedSyntaxError(f"Cannot decorate a class with @cached_property") class AsyncCachedPropertyDecorator(Class): - def bind_decorate_function( + def resolve_decorate_function( self, fn: Function | DecoratedMethod, decorator: expr ) -> Optional[Function | DecoratedMethod]: if fn.klass is not FUNCTION_TYPE: return None return AsyncCachedPropertyMethod(fn, decorator) - def bind_decorate_class(self, klass: Class) -> Class: + def resolve_decorate_class(self, klass: Class) -> Class: raise TypedSyntaxError(f"Cannot decorate a class with @async_cached_property") class IdentityDecorator(Class): - def bind_decorate_function( + def resolve_decorate_function( self, fn: Function | DecoratedMethod, decorator: expr ) -> Optional[Function | DecoratedMethod]: return fn - def bind_decorate_class(self, klass: Class) -> Class: + def resolve_decorate_class(self, klass: Class) -> Class: return klass @@ -6832,7 +6832,7 @@ def make_subclass(self, name: TypeName, bases: List[Class]) -> Class: class ContextDecoratorInstance(Object[ContextDecoratorClass]): - def bind_decorate_function( + def resolve_decorate_function( self, fn: Function | DecoratedMethod, decorator: expr ) -> Optional[Function | DecoratedMethod]: if fn.klass is FUNCTION_TYPE: