"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "interprocedural/callResolution.ml" between
pyre-check-0.0.54.tar.gz and pyre-check-0.0.55.tar.gz

About: Pyre is a performant type checker for Python (ships with Pysa, a security focused static analysis tool).

callResolution.ml  (pyre-check-0.0.54):callResolution.ml  (pyre-check-0.0.55)
skipping to change at line 230 skipping to change at line 230
{ {
Type.Callable.kind = Named name; Type.Callable.kind = Named name;
implementation = implementation =
{ annotation = Type.Any; parameters = Type.Callable.De fined [] }; { annotation = Type.Any; parameters = Type.Callable.De fined [] };
overloads = []; overloads = [];
}, },
Some implementing_class )) Some implementing_class ))
|> Option.value ~default:(None, None) |> Option.value ~default:(None, None)
| _ -> None, None ) | _ -> None, None )
in in
let rec resolve_type callable_type = let rec resolve_type ?(callable_class_type = None) callable_type =
let underlying_callable, self_argument = let underlying_callable, self_argument =
match callable_type with match callable_type with
| Type.Callable underlying_callable -> Some underlying_callable, None | Type.Callable underlying_callable -> Some underlying_callable, None
(* For the case of the LRU cache decorator, the type system loses the call able information as (* For the case of the LRU cache decorator, the type system loses the call able information as
it creates a wrapper class. We reconstruct the underlying callable usin g the implicit. *) it creates a wrapper class. We reconstruct the underlying callable usin g the implicit. *)
| Parametric | Parametric
{ {
name = "BoundMethod"; name = "BoundMethod";
parameters = parameters =
[ [
skipping to change at line 263 skipping to change at line 263
| _ -> None, None ) | _ -> None, None )
| Parametric | Parametric
{ {
name = "BoundMethod"; name = "BoundMethod";
parameters = [Single (Callable underlying_callable); Single self_arg ument]; parameters = [Single (Callable underlying_callable); Single self_arg ument];
} -> } ->
Some underlying_callable, Some self_argument Some underlying_callable, Some self_argument
| _ -> None, None | _ -> None, None
in in
match underlying_callable, self_argument, callable_type, receiver_type, glob al with match underlying_callable, self_argument, callable_type, receiver_type, glob al with
| Some { kind = Named name; _ }, _, _, _, _ when Option.is_some callable_cla
ss_type ->
[Callable.create_method name, callable_class_type]
| Some { kind = Anonymous; _ }, _, _, _, _ when Option.is_some callable_clas
s_type -> (
(* TODO(T66895305): Callable protocols don't retain the name of the call
able, so we special
case them here. *)
match callable_class_type >>= Type.primitive_name with
| Some class_name ->
[`Method { Callable.class_name; method_name = "__call__" }, callable
_class_type]
| None -> [] )
| Some { kind = Named name; _ }, self_argument, _, _, Some _ -> | Some { kind = Named name; _ }, self_argument, _, _, Some _ ->
[Callable.create_function name, self_argument] [Callable.create_function name, self_argument]
| Some { kind = Named name; _ }, self_argument, _, _, _ when is_super_call - > | Some { kind = Named name; _ }, self_argument, _, _, _ when is_super_call - >
[Callable.create_method name, self_argument] [Callable.create_method name, self_argument]
| Some { kind = Named name; _ }, None, _, None, _ when is_all_names -> | Some { kind = Named name; _ }, None, _, None, _ when is_all_names ->
[Callable.create_function name, None] [Callable.create_function name, None]
| Some { kind = Named name; _ }, self_argument, _, _, _ when is_all_names -> | Some { kind = Named name; _ }, self_argument, _, _, _ when is_all_names ->
[Callable.create_method name, self_argument] [Callable.create_method name, self_argument]
| Some { kind = Named name; _ }, self_argument, _, Some type_or_class, _ -> | Some { kind = Named name; _ }, self_argument, _, Some type_or_class, _ ->
compute_indirect_targets ~resolution ~receiver_type:type_or_class name compute_indirect_targets ~resolution ~receiver_type:type_or_class name
skipping to change at line 292 skipping to change at line 301
let name = let name =
Node.value callee Node.value callee
|> (function |> (function
| Name name -> Some name | Name name -> Some name
| _ -> None) | _ -> None)
>>= Ast.Expression.name_to_reference >>= Ast.Expression.name_to_reference
in in
match name with match name with
| Some name -> [Callable.create_function name, None] | Some name -> [Callable.create_function name, None]
| _ -> [] ) | _ -> [] )
(* Handle callable classes. `typing.Type` interacts specially with __call__,
so we choose to
ignore it for now to make sure our constructor logic via `cls()` still wo
rks. *)
| _, _, (Type.Primitive _ | Type.Parametric _), _, _ when not (Type.is_meta
callable_type) -> (
let callable_class_type = callable_type in
match
Resolution.resolve_attribute_access
resolution
~base_type:callable_type
~attribute:"__call__"
with
| Type.Any
| Type.Top ->
[]
| callable_type ->
resolve_type ~callable_class_type:(Some callable_class_type) callabl
e_type )
| _ -> [] | _ -> []
in in
resolve_type callable_type resolve_type callable_type
let get_indirect_targets ~resolution ~receiver ~method_name = let get_indirect_targets ~resolution ~receiver ~method_name =
let receiver_type = resolve_ignoring_optional ~resolution receiver in let receiver_type = resolve_ignoring_optional ~resolution receiver in
let callee = let callee =
Expression.Name (Name.Attribute { base = receiver; attribute = method_name; special = false }) Expression.Name (Name.Attribute { base = receiver; attribute = method_name; special = false })
|> Node.create_with_default_location |> Node.create_with_default_location
in in
 End of changes. 3 change blocks. 
1 lines changed or deleted 33 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)