@@ -744,7 +744,7 @@ let qualify
744744 List. map
745745 decorators
746746 ~f:
747- (qualify_decorator
747+ (qualify_expression
748748 ~qualify_strings: DoNotQualify
749749 ~scope: { scope with use_forward_references = true })
750750 in
@@ -778,7 +778,7 @@ let qualify
778778 }
779779 in
780780 let decorators =
781- List. map decorators ~f: (qualify_decorator ~qualify_strings: DoNotQualify ~scope )
781+ List. map decorators ~f: (qualify_expression ~qualify_strings: DoNotQualify ~scope )
782782 in
783783 let body =
784784 let qualifier = qualify_if_needed ~qualifier name in
@@ -797,21 +797,25 @@ let qualify
797797 let return_annotation =
798798 return_annotation >> | qualify_expression ~scope ~qualify_strings: Qualify
799799 in
800- let qualify_decorator
801- ({ Decorator. name = { Node. value = name ; _ } ; _ } as decorator )
802- =
803- match name |> Reference. as_list |> List. rev with
804- | [" staticmethod" ]
805- | [" classmethod" ]
806- | [" property" ]
807- | " getter" :: _
808- | " setter" :: _
809- | "deleter" :: _ ->
800+ let qualify_decorator decorator =
801+ let is_reserved name =
802+ match Reference. as_list name |> List. rev with
803+ | [" staticmethod" ]
804+ | [" classmethod" ]
805+ | [" property" ]
806+ | " getter" :: _
807+ | " setter" :: _
808+ | "deleter" :: _ ->
809+ true
810+ | _ -> false
811+ in
812+ match Decorator. from_expression decorator with
813+ | Some { Decorator. name = { Node. value = name ; _ } ; _ } when is_reserved name ->
810814 decorator
811815 | _ ->
812816 (* TODO (T41755857): Decorator qualification logic should be slightly more
813817 involved than this. *)
814- qualify_decorator ~qualify_strings: DoNotQualify ~scope decorator
818+ qualify_expression ~qualify_strings: DoNotQualify ~scope decorator
815819 in
816820 let decorators = List. map decorators ~f: qualify_decorator in
817821 let signature =
@@ -1252,11 +1256,6 @@ let qualify
12521256 | Constant _ -> value
12531257 in
12541258 { expression with Node. value }
1255- and qualify_decorator ~qualify_strings ~scope { Decorator. name; arguments } =
1256- {
1257- Decorator. name = Node. map name ~f: (qualify_reference ~scope );
1258- arguments = arguments >> | List. map ~f: (qualify_argument ~qualify_strings ~scope );
1259- }
12601259 and qualify_argument { Call.Argument. name; value } ~qualify_strings ~scope =
12611260 let name =
12621261 let rename identifier =
@@ -3093,15 +3092,11 @@ module AccessCollector = struct
30933092 List. fold base_arguments ~init: collected ~f: (fun sofar { Call.Argument. value; _ } ->
30943093 from_expression sofar value)
30953094 in
3096- List. map decorators ~f: Decorator. to_expression
3097- |> List. fold ~init: collected ~f: from_expression
3095+ List. fold ~init: collected ~f: from_expression decorators
30983096 | Define
30993097 { Define. signature = { Define.Signature. decorators; parameters; return_annotation; _ }; _ }
31003098 ->
3101- let collected =
3102- List. map decorators ~f: Decorator. to_expression
3103- |> List. fold ~init: collected ~f: from_expression
3104- in
3099+ let collected = List. fold ~init: collected ~f: from_expression decorators in
31053100 let collected =
31063101 List. fold
31073102 parameters
@@ -3828,11 +3823,15 @@ let inline_six_metaclass ({ Source.statements; _ } as source) =
38283823 let transform_class
38293824 ~class_statement :({ Class. base_arguments; decorators; _ } as class_statement )
38303825 =
3831- let is_six_add_metaclass_decorator { Decorator. name; _ } =
3832- Identifier. equal (Node. value name |> Reference. show) " six.add_metaclass"
3826+ let is_six_add_metaclass_decorator expression =
3827+ match Decorator. from_expression expression with
3828+ | Some ({ Decorator. name = { Node. value = name; _ }; _ } as decorator)
3829+ when Reference. equal name (Reference. create_from_list [" six" ; " add_metaclass" ]) ->
3830+ Either. First decorator
3831+ | _ -> Either. Second expression
38333832 in
38343833 let six_add_metaclass_decorators, rest =
3835- List. partition_tf decorators ~f: is_six_add_metaclass_decorator
3834+ List. partition_map decorators ~f: is_six_add_metaclass_decorator
38363835 in
38373836 match six_add_metaclass_decorators with
38383837 | [
0 commit comments