Skip to content

Commit

Permalink
Rename ClassDecorators to ExtractDataclassOptions in dataclassOptions
Browse files Browse the repository at this point in the history
Summary:
We are going to expose all dataclass functionality to the typechecker. To do so, we must separate that functionality from attributeResolution.

In this diff, we will rename ClassDecorators to ExtractDataclassOptions.

Reviewed By: stroxler

Differential Revision: D57587117

fbshipit-source-id: 126c3d32ec722d90db71e6e76996ebd1c7c5915b
  • Loading branch information
Zeina Migeed authored and facebook-github-bot committed May 21, 2024
1 parent e18e7be commit c8e02c6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
20 changes: 11 additions & 9 deletions source/analysis/attributeResolution.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1614,7 +1614,7 @@ let apply
| None -> []
| Some
{
ClassDecorators.init;
ExtractDataclassOptions.init;
repr;
eq;
order;
Expand Down Expand Up @@ -1769,10 +1769,11 @@ let apply
let split_parameters_by_keyword_only parameters =
let keyword_only, not_keyword_only =
List.partition_tf parameters ~f:(function
| { ClassDecorators.name = _; annotation = _; default = _; keyword_only } ->
| { ExtractDataclassOptions.name = _; annotation = _; default = _; keyword_only } ->
keyword_only)
in
let dataclass_constructor_to_named { ClassDecorators.name; annotation; default; _ }
let dataclass_constructor_to_named
{ ExtractDataclassOptions.name; annotation; default; _ }
: Type.t Callable.RecordParameter.named
=
{ name; annotation; default }
Expand Down Expand Up @@ -1814,13 +1815,13 @@ let apply
in
let rec override_existing_parameters
(unchecked_parameters :
Type.t ClassDecorators.dataclass_constructor_parameter list)
Type.t ExtractDataclassOptions.dataclass_constructor_parameter list)
=
match unchecked_parameters with
| [] ->
[
{
ClassDecorators.name;
ExtractDataclassOptions.name;
annotation;
default = Option.is_some init_value;
keyword_only;
Expand Down Expand Up @@ -1974,21 +1975,22 @@ let apply
let dataclass_attributes () =
(* TODO (T43210531): Warn about inconsistent annotations
* TODO (T131540506): Decouple dataclass options from other options *)
generate_attributes ~options:(ClassDecorators.dataclass_options ~queries)
generate_attributes ~options:(ExtractDataclassOptions.dataclass_options ~queries)
in
let attrs_attributes () =
(* TODO (T41039225): Add support for other methods
* TODO (T129741558): support type annotations in attr *)
generate_attributes ~options:(ClassDecorators.attrs_attributes ~queries)
generate_attributes ~options:(ExtractDataclassOptions.attrs_attributes ~queries)
in
let dataclass_transform_attributes () =
generate_attributes
~options:(ClassDecorators.options_from_custom_dataclass_transform_decorator ~queries)
~options:(ExtractDataclassOptions.options_from_custom_dataclass_transform_decorator ~queries)
in
let dataclass_transform_class_attributes () =
generate_attributes
~options:
(ClassDecorators.options_from_custom_dataclass_transform_base_class_or_metaclass ~queries)
(ExtractDataclassOptions.options_from_custom_dataclass_transform_base_class_or_metaclass
~queries)
in
dataclass_attributes ()
@ attrs_attributes ()
Expand Down
2 changes: 1 addition & 1 deletion source/analysis/dataclassOptions.ml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ module Queries = struct
Type.split annotation |> fst |> Type.primitive_name >>= get_class_summary
end

module ClassDecorators = struct
module ExtractDataclassOptions = struct
type options = {
init: bool;
repr: bool;
Expand Down
2 changes: 1 addition & 1 deletion source/analysis/dataclassOptions.mli
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ module Queries : sig
val class_summary_for_outer_type : t -> Type.t -> ClassSummary.t Ast.Node.t option
end

module ClassDecorators : sig
module ExtractDataclassOptions : sig
type options = {
init: bool;
repr: bool;
Expand Down

0 comments on commit c8e02c6

Please sign in to comment.