text stringlengths 12 786k |
|---|
let test_boolean_operators context = let assert_type_errors = assert_type_errors ~ context in let assert_default_type_errors = assert_default_type_errors ~ context in assert_type_errors { | from typing import TypeGuard def typeguard_fn ( val : int | str ) -> TypeGuard [ int ] : return True def foo (... |
let test_misc context = let assert_type_errors = assert_type_errors ~ context in assert_type_errors { | from typing import TypeGuard , Union def typeguard_fn ( val : int | str ) -> TypeGuard [ int ] : return True def bool_fn ( val : int | str ) -> bool : return True def first_int ( x : in... |
let ( ) = " type_guard " >::: [ " test_type_guard " >:: test_type_guard ; " test_multiple_arguments " >:: test_multiple_arguments ; " test_methods " >:: test_methods ; " test_callback " >:: test_callback ; " test_return_type " >:: test_return_type ; " test_walrus_operato... |
let filters : ( Sigs_util . plugin_name , Sigs_util . plugin ) Hashtbl . t = Hashtbl . create 30 |
let show_code = ref false |
let print_collect_mtyps = ref false |
let register ? filter ? position = function | ( name , transform ) -> if Hashtbl . mem filters name then eprintf " Warning :% s filter already exists . " !@ name else Hashtbl . add filters name { transform ; position ; filter } |
let show_modules = function | ( ) -> ( Hashtbl . iter ( function | key -> ( function | _ -> Format . printf " % s @ " key ) ) filters ; print_newline ( ) ) |
let plugin_add = function | plugin -> ( ( try let v = Hashtbl . find filters plugin in function | ( ) -> if not @@ ( List . exists ( function | ( n , _ ) -> n = plugin ) ( ! State . current_filters ) ) then Ref . modify State . current_filters ( function | x -> cons (... |
let plugin_remove = function | plugin -> Ref . modify State . current_filters ( function | x -> Listf . remove plugin x ) object inherit Objs . map method get_cur_mtyps : Sigs_util . mtyps method get_cur_and_types : Sigs_util . and_types method update_cur_and_types : ( Sigs_util . and_types ... |
let make_filter = function | ( s , code ) -> let f = function | ( ` StExp ( _loc , ` Lid ( _ , s ' ) ) : Astf . stru ) when s = s ' -> Fill . stru _loc code | e -> e in ( ( " filter_ " ^ s ) , ( ( Objs . map_stru f ) # stru ) ) |
let iterate_code = function | sloc -> ( function | mtyps -> ( function | ( _ , ( x : Sigs_util . plugin ) ) -> ( function | acc -> let mtyps = match x . filter with | Some x -> Sigs_util . apply_filter x mtyps | None -> mtyps in let code = x . transform mtyps in ( match ( ( ... |
let traversal = function | ( ) -> ( object ( self : ' self_type ) inherit Objs . map as super val mtyps_stack = ( Stack . create ( ) : Sigs_util . mtyps Stack . t ) val mutable cur_and_types = ( [ ] : Sigs_util . and_types ) val mutable and_group = false method get_cur_mty... |
let genenrate_type_code = function | _loc -> ( function | tdl -> ( function | ( ns : Astf . strings ) -> ( let x : Astf . stru = ` Type ( _loc , tdl ) in let ns = list_of_app ns [ ] in let filters = List . map ( function | ` Str ( sloc , n ) -> ( match Hashtblf . ... |
let ( ) = Ast2pt . generate_type_code := genenrate_type_code |
let printf_output = if ( try Sys . getenv " DEBUG " = " 1 " with Not_found -> false ) then Format . std_formatter else Format . make_formatter ( fun _ _ _ -> ( ) ) ( fun ( ) -> ( ) ) |
let printf x = Format . fprintf printf_output x |
let type_implicit_instance : ( Env . t -> Typedtree . module_expr -> Path . t -> Longident . t list -> type_expr list -> Typedtree . module_expr * type_expr list ) ref = ref ( fun _ -> assert false ) ) * |
type pending_implicit = { implicit_id : Ident . t ; implicit_env : Env . t ; implicit_loc : Location . t ; implicit_type : Path . t * Longident . t list * type_expr list ; mutable implicit_constraints : ( type_expr * type_expr ) list ; implicit_argument : argument ; } |
let unlink env unlink_on = let path_table = Hashtbl . create 7 in let add_constraint register path ty tyvar = let instance_list = try Hashtbl . find path_table path with Not_found -> [ ] in try let eq_args ( ty ' , _tyvar ' ) = TypeOps . equal ty ty ' || Ctype . equal env false [ ty ]... |
let pending_implicits : pending_implicit list list ref = ref [ ] |
let rec has_implicit ty = match ( repr ty ) . desc with | Tarrow ( Tarr_implicit id , _ , _ , _ ) -> true | Tarrow ( _ , _ , rhs , _ ) -> has_implicit rhs | _ -> false |
let instantiate_one_implicit loc env id ty_arg ty_res = let inst = match ( repr ty_arg ) . desc with | Tpackage ( p , nl , tl ) -> { implicit_id = id ; implicit_env = env ; implicit_loc = loc ; implicit_type = ( p , nl , tl ) ; implicit_constraints = [ ] ; implicit_argumen... |
let pack_implicit_ref : ( pending_implicit -> Path . t -> Typedtree . expression ) ref = ref ( fun _ _ -> assert false ) |
let pack_implicit inst path = ! pack_implicit_ref inst path |
module Link = struct let to_path inst path = let subst = Subst . add_module inst . implicit_id path Subst . identity in List . iter ( fun ( ty , tyvar ) -> let ty = Subst . type_expr subst ty in let tyvar = Subst . type_expr subst tyvar in unify inst . implicit_env ty tyvar ) inst . impl... |
let reunify_constraint inst = let reunify ( ty , tyvar ) = try unify inst . implicit_env ty tyvar with _ -> ( ) in List . iter reunify inst . implicit_constraints |
let reunify_constraints ( ) = List . iter ( List . iter reunify_constraint ) ! pending_implicits |
let add_pending_implicits insts = pending_implicits := insts :: ! pending_implicits |
let reset_pending_implicits ( ) = pending_implicits := [ ] |
let generalize_implicits_ref : ( unit -> unit ) ref = ref ( fun ( ) -> assert false ) |
let generalize_implicits ( ) = ! generalize_implicits_ref ( ) |
let type_to_string type_ = type_ |> Format . asprintf " % a " Type . pp |
let type_to_reference type_ = type_ |> type_to_string |> Reference . create |
let expression_to_json expression = ` String ( expression |> Expression . sanitized |> Expression . show ) |
module SerializableReference = struct type t = Reference . t [ @@ deriving compare , sexp , hash , show ] let to_yojson reference = ` String ( Reference . show_sanitized reference ) module Map = Reference . Map . Tree module Set = Set . Make ( Reference ) end |
module DefaultValue = struct type t = Expression . t option [ @@ deriving show ] let to_yojson value = value >>| expression_to_json |> Option . value ~ default ` : Null end |
module AnnotationLocation = struct type t = { qualifier : SerializableReference . t ; path : string ; line : int ; } [ @@ deriving show , compare , to_yojson ] let create ~ lookup ~ qualifier ~ line = { qualifier ; path = lookup qualifier |> Option . value ~ default " " ; :... |
module SerializableType = struct type t = Type . t [ @@ deriving show ] let to_yojson type_ = ` String ( type_to_string type_ ) end |
module TypeAnnotation = struct type t = | Inferred of SerializableType . t | Given of Expression . t | Missing [ @@ deriving show ] let is_inferred = function | Inferred _ -> true | Given _ | Missing -> false let from_given maybe_expression = match maybe_expression with | Some expression -> Giv... |
module AnnotationsByName = struct module Base = struct module type S = sig type t [ @@ deriving show , compare , to_yojson ] val identifying_name : t -> SerializableReference . t end module Make ( Value : S ) = struct type t = Value . t SerializableReference . Map . t let empty = Serializa... |
module GlobalAnnotation = struct module Value = struct type t = { name : SerializableReference . t ; location : AnnotationLocation . t ; annotation : SerializableType . t ; } [ @@ deriving show , to_yojson ] let compare { location = left ; _ } { location = right ; _ } = Ann... |
module AttributeAnnotation = struct module Value = struct type t = { parent : SerializableReference . t ; name : SerializableReference . t ; location : AnnotationLocation . t ; annotation : SerializableType . t ; } [ @@ deriving show , to_yojson ] let compare { location = left ; _... |
module DefineAnnotation = struct module Parameters = struct module Value = struct type t = { name : SerializableReference . t ; annotation : TypeAnnotation . t ; value : DefaultValue . t ; index : int ; } [ @@ deriving show , to_yojson ] let compare { index = left ; _ } { inde... |
module Inference = struct type target = | Return | Parameter of { name : Reference . t } | Global of { name : Reference . t ; location : Location . WithModule . t ; } | Attribute of { parent : Reference . t ; name : Reference . t ; location : Location . WithModule . t ; }... |
module LocalResult = struct type t = { globals : GlobalAnnotation . ByName . t ; attributes : AttributeAnnotation . ByName . t ; define : DefineAnnotation . t ; } [ @@ deriving show , to_yojson ] let define_name { define = { name ; _ } ; _ } = name let from_signature ~ g... |
module GlobalResult = struct module DefineAnnotationsByName = struct module Value = struct type t = DefineAnnotation . t [ @@ deriving show , compare , to_yojson ] let identifying_name { DefineAnnotation . name ; _ } = name end include AnnotationsByName . Base . Make ( Value ) end type ... |
let environment_data scratch_project = let { ScratchProject . BuiltGlobalEnvironment . global_environment ; _ } = scratch_project |> ScratchProject . build_global_environment in global_environment , scratch_project . configuration |
let type_inference_result ~ context ~ test_source = let scratch_project = ScratchProject . setup ~ context [ " test . py " , test_source ] in let global_environment , configuration = scratch_project |> environment_data in let scheduler = Test . mock_scheduler ( ) in let global_result = Se... |
let assert_json_equal ~ context ~ expected result = let expected = Yojson . Safe . from_string expected in assert_equal ~ ctxt : context ~ printer : Yojson . Safe . pretty_to_string ~ msg " : GlobalResult json " expected result |
let assert_global_result ~ context ~ test_source ~ expected ( ) = let result = type_inference_result ~ context ~ test_source in result |> TypeInference . Data . GlobalResult . to_yojson |> assert_json_equal ~ context ~ expected |
let serialization_test context = assert_global_result ~ context ~ test_source : { | import functools from sqlalchemy import Integer x = 1 + 1 class C : x = 1 + 1 def no_errors ( x : int ) -> int : return x @ functools . lru_cache ( 4 ) def needs_return ( y : C , x : Integer ) : r... |
let duplicate_define_test context = assert_global_result ~ context ~ test_source : { | import typing @ typing . overload def f ( x : int , y ) -> int : y = " y " return x @ typing . overload def f ( x : str , y ) -> str : y = " y " return x @ typing . overload def f ( x : ... |
let suppress_test context = assert_global_result ~ context ~ test_source { :| x = None class Foo : x = None } | ~ expected : { | { " globals " : [ ] , " attributes " : [ ] , " defines " : [ ] } } | ( ) |
let attribute_widen_test context = assert_global_result ~ context ~ test_source : { | class Foo : x = None def __init__ ( self ) -> None : self . x = 1 + 1 } | ~ expected : { | { " globals " : [ ] , " attributes " : [ { " parent " : " test . Foo " , " n... |
let ( ) = " typeInferenceAnalysisTest " >::: [ " serialization " >:: serialization_test ; " duplicates " >:: duplicate_define_test ; " suppress " >:: suppress_test ; " attribute_widen " >:: attribute_widen_test ; ] |> Test . run |
let refine_local ~ resolution ~ name ~ annotation = match name_to_reference name with | Some reference -> Resolution . refine_local resolution ~ reference ~ annotation | None -> resolution |
module ErrorMap = struct type key = { location : Location . t ; kind : int ; } [ @@ deriving compare , sexp ] module Map = Map . Make ( struct type nonrec t = key let compare = compare_key let sexp_of_t = sexp_of_key let t_of_sexp = key_of_sexp end ) let add ~ errors ( { Error . l... |
module type Context = sig val configuration : Configuration . Analysis . t val qualifier : Reference . t val define : Define . t Node . t val resolution_fixpoint : LocalAnnotationMap . t option val error_map : TypeCheck . LocalErrorMap . t option end |
module type Signature = sig type t [ @@ deriving eq ] val create : ? bottom : bool -> resolution : Resolution . t -> unit -> t val initial : resolution : Resolution . t -> t val initial_forward : resolution : Resolution . t -> t val initial_backward : forward : t -> t val widen_resolution_wi... |
module State ( Context : Context ) = struct module TypeCheckContext = struct let qualifier = Context . qualifier let debug = Context . configuration . debug let constraint_solving_style = Configuration . Analysis . default_constraint_solving_style let define = Context . define let resolution_fixp... |
let infer_local ~ configuration ~ global_resolution ~ source { : Source . source_path = { ModulePath . qualifier ; _ } ; _ } ~ define : ( { Node . location ; value = { Define . signature = { name ; _ } ; _ } as define } as define_node ) = let module State = State... |
let infer_parameters_from_parent ~ global_resolution ~ source { : Source . source_path = { ModulePath . qualifier ; _ } ; _ } ~ define ( { : Node . value = { Define . signature = { parent ; parameters ; _ } ; _ } ; _ } as define ) = let overridden_callable = pa... |
let merge_errors ~ global_resolution errors = errors |> List . map ~ f ( : fun ( { Error . kind ; _ } as error ) -> { error with kind = Error . weaken_literals kind } ) |> Error . join_at_source ~ resolution : global_resolution |> List . sort ~ compare : Error . compare |
let legacy_infer_for_define ~ configuration ~ global_resolution ~ source ( { : Source . source_path = { ModulePath . qualifier ; relative ; _ } ; _ } as source ) ~ define ( { : Node . location ; value = { Define . signature = { name ; _ } ; _ } } as define ) ... |
let infer_for_define ~ configuration ~ global_resolution ~ source ~ qualifier ~ filename_lookup ~ define = let timer = Timer . start ( ) in let { Node . location ; value = { Define . signature ; _ } } = define in let abstract = Define . Signature . is_abstract_method signature in l... |
let should_analyze_define ~ skip_annotated ~ global_resolution { Node . value = { Define . signature = { return_annotation ; parameters ; _ } ; _ } as define ; _ } = let alias_environment = GlobalResolution . alias_environment global_resolution in let is_missing_or_invalid maybe_expre... |
let empty_infer_for_define ~ global_resolution ~ qualifier ~ define = let lookup _ = None in TypeInferenceData . LocalResult . from_signature ~ global_resolution ~ lookup ~ qualifier define |
let infer_for_module ( ? skip_annotated = true ) ~ configuration ~ global_resolution ~ filename_lookup ( { Ast . Source . source_path = { qualifier ; _ } as source_path ; _ } as source ) = Log . debug " Running infer for % s . . . " source_path . relative ; let check de... |
module Testing = struct let define_names_to_analyze ~ global_resolution source = source |> Preprocessing . defines ~ include_toplevels : true |> List . filter ~ f ( : should_analyze_define ~ skip_annotated : true ~ global_resolution ) |> List . map ~ f ( : fun define -> define |> Node . v... |
let configuration = Configuration . Analysis . create ~ source_paths [ ] : ( ) |
let assert_backward ~ resolution precondition statement postcondition = let module State = State ( struct let qualifier = Reference . empty let configuration = configuration let define = + mock_define let resolution_fixpoint = Some ( LocalAnnotationMap . empty ( ) ) let error_map = Some ( TypeC... |
let test_backward_resolution_handling context = let resolution = ScratchProject . setup ~ context [ ] |> ScratchProject . build_resolution in let assert_backward = assert_backward ~ resolution in assert_backward [ " y " , Type . integer ] " pass " [ " y " , Type . integer ] ; ... |
let test_inferred_function_parameters context = let check_inference_results = check_inference_results ~ field_path [ " : define " ; " parameters " ] ~ context in let single_parameter ( ? name = " x " ) ? default type_ = Format . asprintf { | [ { " name " : " % s " , "... |
let test_inferred_method_parameters context = let check_inference_results = check_inference_results ~ context ~ field_path [ " : define " ; " parameters " ] in let single_parameter_method type_ = Format . asprintf { | [ { " name " : " self " , " annotation " : null , " v... |
let test_inferred_globals context = let check_inference_results = check_inference_results ~ context ~ field_path [ " : globals " ] in check_inference_results { | def foo ( ) -> int : return 1234 x = foo ( ) } | ~ target " : test . $ toplevel " ~ expected : { | [ { " na... |
let test_inferred_attributes context = let check_inference_results = check_inference_results ~ context ~ field_path [ " : attributes " ] in check_inference_results { | def foo ( ) -> int : return 1 class Foo : x = foo ( ) } | ~ target " : test . Foo . $ class_toplevel " ~ exp... |
let ( ) = " typeInferenceLocalTest " >::: [ " test_backward_resolution_handling " >:: test_backward_resolution_handling ; " test_should_analyze_define " >:: test_should_analyze_define ; " test_inferred_returns " >:: test_inferred_returns ; " test_inferred_function_parameters " >:: ... |
type conversion_function = JavaAST . expression -> JavaAST . expression |
type t = { ocaml_type : Path . t option ; java_type : JavaAST . type_ ; java_of_ocaml : conversion_function ; ocaml_of_java : conversion_function ; } |
let make_simple ident = let path = Path . Pident ident in let name = Ident . name ident in let info = { ocaml_type = Some path ; java_type = JavaAST . Reference ( name , [ ] ) ; java_of_ocaml = ( fun e -> JavaAST . Static_call ( name , " wrap " , [ e ] e ) e ) e ; ocaml_o... |
let type_int = { ocaml_type = Some Predef . path_int ; java_type = JavaAST . Long ; java_of_ocaml = ( fun e -> JavaAST . Call ( e , " asLong " , [ ] ) ) ; ocaml_of_java = ( fun e -> JavaAST . Static_call ( " Value " , " createLong " , [ e ] e ) e ) e ; } |
let type_int_boxed = { ocaml_type = Some Predef . path_int ; java_type = JavaAST . Reference ( " OCamlInt " , [ ] ) ; java_of_ocaml = ( fun e -> JavaAST . Static_call ( " OCamlInt " , " wrap " , [ e ] e ) e ) e ; ocaml_of_java = ( fun e -> JavaAST . Call ( e , "... |
let type_char = { ocaml_type = Some Predef . path_char ; java_type = JavaAST . Int ; java_of_ocaml = ( fun e -> JavaAST . Call ( e , " asCastedInt " , [ ] ) ) ; ocaml_of_java = ( fun e -> JavaAST . Static_call ( " Value " , " createLong " , [ e ] e ) e ) e ; ... |
let type_char_boxed = { ocaml_type = Some Predef . path_char ; java_type = JavaAST . Reference ( " OCamlChar " , [ ] ) ; java_of_ocaml = ( fun e -> JavaAST . Static_call ( " OCamlChar " , " wrap " , [ e ] e ) e ) e ; ocaml_of_java = ( fun e -> JavaAST . Call ( e ,... |
let type_string = { ocaml_type = Some Predef . path_string ; java_type = JavaAST . Reference ( " String " , [ ] ) ; java_of_ocaml = ( fun e -> JavaAST . Call ( e , " asString " , [ ] ) ) ; ocaml_of_java = ( fun e -> JavaAST . Static_call ( " Value " , " create... |
let type_string_boxed = { ocaml_type = Some Predef . path_string ; java_type = JavaAST . Reference ( " OCamlString " , [ ] ) ; java_of_ocaml = ( fun e -> JavaAST . Static_call ( " OCamlString " , " wrap " , [ e ] e ) e ) e ; ocaml_of_java = ( fun e -> JavaAST . Call ... |
let type_byte_array = { ocaml_type = Some Predef . path_string ; java_type = JavaAST . Array JavaAST . Byte ; java_of_ocaml = ( fun e -> JavaAST . Call ( e , " getBytesForModification " , [ ] ) ) ; ocaml_of_java = ( fun e -> JavaAST . Static_call ( " Value " , " createS... |
let type_float = { ocaml_type = Some Predef . path_float ; java_type = JavaAST . Double ; java_of_ocaml = ( fun e -> JavaAST . Call ( e , " asDouble " , [ ] ) ) ; ocaml_of_java = ( fun e -> JavaAST . Static_call ( " Value " , " createDouble " , [ e ] e ) e ) e ... |
let type_float_boxed = { ocaml_type = Some Predef . path_float ; java_type = JavaAST . Reference ( " OCamlFloat " , [ ] ) ; java_of_ocaml = ( fun e -> JavaAST . Static_call ( " OCamlFloat " , " wrap " , [ e ] e ) e ) e ; ocaml_of_java = ( fun e -> JavaAST . Call ( ... |
let type_bool = { ocaml_type = Some Predef . path_bool ; java_type = JavaAST . Boolean ; java_of_ocaml = ( fun e -> JavaAST . Static_call ( " OCamlWrappers " , " asBool " , [ e ] e ) e ) e ; ocaml_of_java = ( fun e -> JavaAST . Static_call ( " OCamlWrappers " , " creat... |
let type_bool_boxed = { ocaml_type = Some Predef . path_bool ; java_type = JavaAST . Reference ( " OCamlBool " , [ ] ) ; java_of_ocaml = ( fun e -> JavaAST . Static_call ( " OCamlBool " , " wrap " , [ e ] e ) e ) e ; ocaml_of_java = ( fun e -> JavaAST . Call ( e ,... |
let type_unit_boxed = { ocaml_type = Some Predef . path_unit ; java_type = JavaAST . Reference ( " OCamlUnit " , [ ] ) ; java_of_ocaml = ( fun e -> JavaAST . Static_call ( " OCamlUnit " , " wrap " , [ e ] e ) e ) e ; ocaml_of_java = ( fun e -> JavaAST . Call ( e ,... |
let type_nativeint = { ocaml_type = Some Predef . path_nativeint ; java_type = JavaAST . Long ; java_of_ocaml = ( fun e -> JavaAST . Call ( e , " asNativeInt " , [ ] ) ) ; ocaml_of_java = ( fun e -> JavaAST . Static_call ( " Value " , " createNativeInt " , [ e ] e ... |
let type_nativeint_boxed = { ocaml_type = Some Predef . path_nativeint ; java_type = JavaAST . Reference ( " OCamlNativeInt " , [ ] ) ; java_of_ocaml = ( fun e -> JavaAST . Static_call ( " OCamlNativeInt " , " wrap " , [ e ] e ) e ) e ; ocaml_of_java = ( fun e -> Jav... |
let type_int32 = { ocaml_type = Some Predef . path_int32 ; java_type = JavaAST . Int ; java_of_ocaml = ( fun e -> JavaAST . Call ( e , " asInt32 " , [ ] ) ) ; ocaml_of_java = ( fun e -> JavaAST . Static_call ( " Value " , " createInt32 " , [ e ] e ) e ) e ; }... |
let type_int32_boxed = { ocaml_type = Some Predef . path_int32 ; java_type = JavaAST . Reference ( " OCamlInt32 " , [ ] ) ; java_of_ocaml = ( fun e -> JavaAST . Static_call ( " OCamlInt32 " , " wrap " , [ e ] e ) e ) e ; ocaml_of_java = ( fun e -> JavaAST . Call ( ... |
let type_int64 = { ocaml_type = Some Predef . path_int64 ; java_type = JavaAST . Long ; java_of_ocaml = ( fun e -> JavaAST . Call ( e , " asInt64 " , [ ] ) ) ; ocaml_of_java = ( fun e -> JavaAST . Static_call ( " Value " , " createInt64 " , [ e ] e ) e ) e ; ... |
let type_int64_boxed = { ocaml_type = Some Predef . path_int64 ; java_type = JavaAST . Reference ( " OCamlInt64 " , [ ] ) ; java_of_ocaml = ( fun e -> JavaAST . Static_call ( " OCamlInt64 " , " wrap " , [ e ] e ) e ) e ; ocaml_of_java = ( fun e -> JavaAST . Call ( ... |
let type_array = { ocaml_type = Some Predef . path_array ; java_type = JavaAST . Reference ( " OCamlArray " , [ ] ) ; java_of_ocaml = ( fun e -> JavaAST . Static_call ( " OCamlArray " , " wrap " , [ e ] e ) e ) e ; ocaml_of_java = ( fun e -> JavaAST . Call ( e , ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.