"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "analysis/preprocessing.ml" between
pyre-check-0.0.53.tar.gz and pyre-check-0.0.54.tar.gz

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

preprocessing.ml  (pyre-check-0.0.53):preprocessing.ml  (pyre-check-0.0.54)
skipping to change at line 1512 skipping to change at line 1512
(* Add `from.name -> name`. *) (* Add `from.name -> name`. *)
Map.set map ~key:(Reference.combine from name) ~data:name Map.set map ~key:(Reference.combine from name) ~data:name
in in
List.fold_left imports ~f:add_import ~init:map, [statement] List.fold_left imports ~f:add_import ~init:map, [statement]
| _ -> map, [statement] | _ -> map, [statement]
end) end)
in in
let map = Map.set ~key:qualifier ~data:Reference.empty Reference.Map.empty in let map = Map.set ~key:qualifier ~data:Reference.empty Reference.Map.empty in
ImportDequalifier.transform map source |> fun { ImportDequalifier.state; _ } - > state ImportDequalifier.transform map source |> fun { ImportDequalifier.state; _ } - > state
let is_lazy_import { Node.value; _ } =
match value with
| Expression.Name name -> (
match name_to_reference name with
| Some reference
when String.Set.mem Recognized.lazy_import_functions (Reference.show ref
erence) ->
true
| _ -> false )
| _ -> false
let replace_lazy_import ?(is_lazy_import = is_lazy_import) source =
let module LazyImportTransformer = Transform.MakeStatementTransformer (struct
type t = unit
let statement _ ({ Node.value; location } as statement) =
match value with
| Statement.Assign
{
Assign.target =
{
Node.value = Expression.Name (Name.Identifier identifier);
location = identifier_location;
};
value =
{
Node.value =
Expression.Call
{
callee;
arguments =
[
{
Call.Argument.value =
{
Node.value =
Expression.String { StringLiteral.kind = Strin
g; value = literal };
location = literal_location;
};
_;
};
];
};
_;
};
_;
}
when is_lazy_import callee ->
( (),
[
Statement.Import
{
from = None;
imports =
[
{
Import.name =
Reference.create literal |> Node.create ~location:lite
ral_location;
alias =
Some
( Identifier.sanitized identifier
|> Node.create ~location:identifier_location );
};
];
}
|> Node.create ~location;
] )
| Statement.Assign
{
Assign.target =
{
Node.value = Expression.Name (Name.Identifier identifier);
location = identifier_location;
};
value =
{
Node.value =
Expression.Call
{
callee;
arguments =
[
{
Call.Argument.value =
{
Node.value =
Expression.String
{ StringLiteral.kind = String; value = from_
literal };
location = from_literal_location;
};
_;
};
{
Call.Argument.value =
{
Node.value =
Expression.String
{ StringLiteral.kind = String; value = impor
t_literal };
location = import_literal_location;
};
_;
};
];
};
_;
};
_;
}
when is_lazy_import callee ->
( (),
[
Statement.Import
{
from =
Some
(Reference.create from_literal |> Node.create ~location:fr
om_literal_location);
imports =
[
{
Import.name =
Reference.create import_literal
|> Node.create ~location:import_literal_location;
alias =
Some
( Identifier.sanitized identifier
|> Node.create ~location:identifier_location );
};
];
}
|> Node.create ~location;
] )
| _ -> (), [statement]
end)
in
LazyImportTransformer.transform () source |> LazyImportTransformer.source
let replace_mypy_extensions_stub let replace_mypy_extensions_stub
({ Source.source_path = { SourcePath.relative; _ }; statements; _ } as sourc e) ({ Source.source_path = { SourcePath.relative; _ }; statements; _ } as sourc e)
= =
if String.is_suffix relative ~suffix:"mypy_extensions.pyi" then if String.is_suffix relative ~suffix:"mypy_extensions.pyi" then
let typed_dictionary_stub ~location = let typed_dictionary_stub ~location =
let node value = Node.create ~location value in let node value = Node.create ~location value in
Statement.Assign Statement.Assign
{ {
target = node (Expression.Name (Name.Identifier "TypedDict")); target = node (Expression.Name (Name.Identifier "TypedDict"));
annotation = annotation =
skipping to change at line 2918 skipping to change at line 3053
|> replace_version_specific_code |> replace_version_specific_code
|> expand_type_checking_imports |> expand_type_checking_imports
|> expand_string_annotations |> expand_string_annotations
|> expand_format_string |> expand_format_string
|> expand_implicit_returns |> expand_implicit_returns
let preprocess_phase1 source = let preprocess_phase1 source =
source source
|> populate_unbound_names |> populate_unbound_names
|> qualify |> qualify
|> replace_lazy_import
|> replace_mypy_extensions_stub |> replace_mypy_extensions_stub
|> expand_typed_dictionary_declarations |> expand_typed_dictionary_declarations
|> expand_sqlalchemy_declarative_base |> expand_sqlalchemy_declarative_base
|> expand_named_tuples |> expand_named_tuples
|> expand_new_types |> expand_new_types
|> populate_nesting_defines |> populate_nesting_defines
|> populate_captures |> populate_captures
let preprocess source = preprocess_phase0 source |> preprocess_phase1 let preprocess source = preprocess_phase0 source |> preprocess_phase1
 End of changes. 2 change blocks. 
0 lines changed or deleted 142 lines changed or added

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