Skip to content

Commit

Permalink
Change the interpretation of parameter locations back
Browse files Browse the repository at this point in the history
Reviewed By: dkgi

Differential Revision: D33465811

fbshipit-source-id: cf548f1b61b450049b5ac02482f04348f61f18a5
  • Loading branch information
grievejia authored and facebook-github-bot committed Jan 7, 2022
1 parent 6345198 commit d3012ee
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 22 deletions.
15 changes: 15 additions & 0 deletions source/analysis/lookup.ml
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,21 @@ module Visit = struct
({ Define.signature = { name; parameters; decorators; return_annotation; _ }; _ } as
define) ->
let visit_parameter { Node.value = { Parameter.annotation; value; name }; location } =
(* Location in the AST includes both the parameter name and the annotation. For our
purpose, we just need the location of the name. *)
let location =
let { Location.start = { Location.line = start_line; column = start_column }; _ } =
location
in
{
Location.start = { Location.line = start_line; column = start_column };
stop =
{
Location.line = start_line;
column = start_column + String.length (Identifier.sanitized name);
};
}
in
Expression.Name (Name.Identifier name) |> Node.create ~location |> postcondition_visit;
Option.iter ~f:postcondition_visit value;
annotation >>| store_annotation |> ignore
Expand Down
22 changes: 11 additions & 11 deletions source/analysis/test/lookupTest.ml
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,12 @@ let test_lookup_pick_narrowest context =
~lookup
[
"2:14-2:18/typing.Type[bool]";
"2:20-2:49/typing.Optional[bool]";
"2:20-2:26/typing.Optional[bool]";
"2:28-2:49/typing.Type[typing.Optional[bool]]";
"2:4-2:7/typing.Callable(test.foo)[[Named(flag, bool), Named(testme, \
typing.Optional[bool])], None]";
"2:54-2:58/None";
"2:8-2:18/bool";
"2:8-2:12/bool";
"3:17-3:27/bool";
"3:21-3:27/typing.Optional[bool]";
"3:7-3:11/bool";
Expand Down Expand Up @@ -262,7 +262,7 @@ let test_lookup_attributes context =
"3:4-3:5/int";
"3:7-3:10/typing.Type[int]";
"4:17-4:21/test.A";
"4:23-4:29/int";
"4:23-4:24/int";
"4:26-4:29/typing.Type[int]";
"4:34-4:38/None";
"4:8-4:16/typing.Callable(test.A.__init__)[[Named(self, test.A), Named(i, int)], None]";
Expand Down Expand Up @@ -495,7 +495,7 @@ let test_lookup_comprehensions context =
[
"2:6-2:9/typing.Type[test.Foo]";
"3:15-3:19/test.Foo";
"3:21-3:27/int";
"3:21-3:22/int";
"3:24-3:27/typing.Type[int]";
"3:32-3:36/None";
"3:6-3:14/typing.Callable(test.Foo.__init__)[[Named(self, test.Foo), Named(x, int)], None]";
Expand Down Expand Up @@ -664,11 +664,11 @@ let test_lookup_if_statements context =
~lookup
[
"2:14-2:18/typing.Type[bool]";
"2:20-2:42/typing.List[int]";
"2:20-2:24/typing.List[int]";
"2:26-2:42/typing.Type[typing.List[int]]";
"2:4-2:7/typing.Callable(test.foo)[[Named(flag, bool), Named(list, typing.List[int])], None]";
"2:47-2:51/None";
"2:8-2:18/bool";
"2:8-2:12/bool";
"3:7-3:11/bool";
"5:11-5:15/bool";
"5:7-5:15/bool";
Expand Down Expand Up @@ -728,13 +728,13 @@ let test_lookup_string_annotations context =
~lookup
[
"2:4-2:7/typing.Callable(test.foo)[[Named(x, int), Named(y, str)], None]";
"3:3-3:11/int";
"3:3-3:4/int";
"3:6-3:11/typing.Type[int]";
"4:3-4:11/str";
"4:3-4:4/str";
"4:6-4:11/typing.Type[str]";
"5:5-5:9/None";
];
assert_annotation ~position:{ Location.line = 3; column = 3 } ~annotation:(Some "3:3-3:11/int");
assert_annotation ~position:{ Location.line = 3; column = 3 } ~annotation:(Some "3:3-3:4/int");
assert_annotation
~position:{ Location.line = 3; column = 6 }
~annotation:(Some "3:6-3:11/typing.Type[int]");
Expand All @@ -745,7 +745,7 @@ let test_lookup_string_annotations context =
~position:{ Location.line = 3; column = 10 }
~annotation:(Some "3:6-3:11/typing.Type[int]");
assert_annotation ~position:{ Location.line = 3; column = 11 } ~annotation:None;
assert_annotation ~position:{ Location.line = 4; column = 3 } ~annotation:(Some "4:3-4:11/str");
assert_annotation ~position:{ Location.line = 4; column = 3 } ~annotation:(Some "4:3-4:4/str");
assert_annotation
~position:{ Location.line = 4; column = 6 }
~annotation:(Some "4:6-4:11/typing.Type[str]");
Expand Down Expand Up @@ -776,7 +776,7 @@ let test_lookup_unbound context =
"2:14-2:29/typing.Type[typing.List[Variable[_T]]]";
"2:34-2:38/None";
"2:4-2:7/typing.Callable(test.foo)[[Named(list, typing.List[Variable[_T]])], None]";
"2:8-2:29/typing.List[Variable[_T]]";
"2:8-2:12/typing.List[Variable[_T]]";
"3:13-3:14/typing.Any";
"3:18-3:20/typing.List[Variable[_T]]";
"3:2-3:3/typing.List[typing.Any]";
Expand Down
22 changes: 11 additions & 11 deletions source/server/test/queryTest.ml
Original file line number Diff line number Diff line change
Expand Up @@ -414,10 +414,10 @@ let test_handle_query_basic context =
};
overloads = [];
} );
2, 8, 2, 14, Type.integer;
2, 8, 2, 9, Type.integer;
2, 11, 2, 14, Type.meta Type.integer;
2, 17, 2, 19, Type.literal_integer 10;
2, 21, 2, 27, Type.string;
2, 21, 2, 22, Type.string;
2, 24, 2, 27, Type.meta Type.string;
2, 30, 2, 35, Type.literal_string "bar";
2, 40, 2, 44, Type.none;
Expand Down Expand Up @@ -474,9 +474,9 @@ let test_handle_query_basic context =
};
overloads = [];
} );
2, 8, 2, 14, Type.integer;
2, 8, 2, 9, Type.integer;
2, 11, 2, 14, Type.meta Type.integer;
2, 16, 2, 22, Type.string;
2, 16, 2, 17, Type.string;
2, 19, 2, 22, Type.meta Type.string;
2, 27, 2, 30, Type.meta Type.string;
3, 1, 3, 2, Type.integer;
Expand Down Expand Up @@ -719,12 +719,12 @@ let test_handle_query_basic context =
};
overloads = [];
} );
2, 8, 2, 14, Type.integer;
2, 11, 2, 14, parse_annotation "typing.Type[int]";
2, 19, 2, 22, parse_annotation "typing.Type[str]";
3, 10, 3, 16, Type.integer;
3, 13, 3, 16, parse_annotation "typing.Type[int]";
3, 21, 3, 24, parse_annotation "typing.Type[str]";
2, 8, 2, 9, Type.integer;
2, 11, 2, 14, Type.meta Type.integer;
2, 19, 2, 22, Type.meta Type.string;
3, 10, 3, 11, Type.integer;
3, 13, 3, 16, Type.meta Type.integer;
3, 21, 3, 24, Type.meta Type.string;
4, 11, 4, 12, Type.integer;
5, 9, 5, 10, Type.integer;
]
Expand Down Expand Up @@ -769,7 +769,7 @@ let test_handle_query_basic context =
};
overloads = [];
} );
2, 8, 2, 27, Type.list Type.integer;
2, 8, 2, 9, Type.list Type.integer;
2, 11, 2, 27, Type.meta (Type.list Type.integer);
2, 32, 2, 36, Type.none;
]
Expand Down

0 comments on commit d3012ee

Please sign in to comment.