text stringlengths 0 601k |
|---|
let test_parse_type_variable_declarations _ = let assert_parses_declaration expression expected = assert_equal ( Some expected ) ( Type . Variable . parse_declaration ( parse_single_expression expression ) ~ target ( : Reference . create " target " ) ) in let assert_declaration_does_not_parse expression = assert_equal ... |
let test_starred_annotation_expression _ = let assert_starred_expression concatenation expression = assert_equal ~ printer : Expression . show ~ cmp ( : fun left right -> Expression . location_insensitive_compare left right = 0 ) ( parse_single_expression ~ coerce_special_methods : true expression ) ( Type . OrderedTyp... |
let test_concatenation_from_unpack_expression _ = let variadic = Type . Variable . Variadic . Tuple . create " Ts " in let assert_concatenation expression concatenation = let parse_annotation expression = let aliases ? replace_unbound_parameters_with_any : _ = function | " Ts " -> Some ( Type . VariableAlias ( Type . V... |
let test_broadcast _ = let assert_broadcast left_type right_type expected = assert_equal ~ printer [ :% show : Type . t ] ~ cmp [ :% equal : Type . t ] ( Type . OrderedTypes . broadcast left_type right_type ) expected ; assert_equal ~ printer [ :% show : Type . t ] ~ cmp [ :% equal : Type . t ] ( Type . OrderedTypes . ... |
let test_split_ordered_types _ = let variadic = Type . Variable . Variadic . Tuple . create " Ts " in let assert_split ( ? split_both_ways = true ) left right expected = let aliases ? replace_unbound_parameters_with_any : _ = function | " Ts " -> Some ( Type . VariableAlias ( Type . Variable . TupleVariadic variadic ) ... |
let test_coalesce_ordered_types _ = let variadic = Type . Variable . Variadic . Tuple . create " Ts " in let assert_coalesce ordered_types expected = let aliases ? replace_unbound_parameters_with_any : _ = function | " Ts " -> Some ( Type . VariableAlias ( Type . Variable . TupleVariadic variadic ) ) | _ -> None in let... |
let test_drop_prefix_ordered_type _ = let open Type . OrderedTypes in let assert_drop_prefix ~ length actual expected_tuple = let variadic = Type . Variable . Variadic . Tuple . create " Ts " in let aliases ? replace_unbound_parameters_with_any : _ = function | " Ts " -> Some ( Type . VariableAlias ( Type . Variable . ... |
let test_index_ordered_type _ = let assert_index ~ python_index tuple expected = let variadic = Type . Variable . Variadic . Tuple . create " Ts " in let aliases ? replace_unbound_parameters_with_any : _ = function | " Ts " -> Some ( Type . VariableAlias ( Type . Variable . TupleVariadic variadic ) ) | _ -> None in let... |
let test_zip_variables_with_parameters _ = let unary = Type . Variable . Unary . create " T " in let unary2 = Type . Variable . Unary . create " T2 " in let variadic = Type . Variable . Variadic . Tuple . create " Ts " in let variadic2 = Type . Variable . Variadic . Tuple . create " Ts2 " in let parameter_variadic = Ty... |
let test_zip_on_two_parameter_lists _ = let unary = Type . Variable . Unary . create " T " in let unary2 = Type . Variable . Unary . create " T2 " in let variadic = Type . Variable . Variadic . Tuple . create " Ts " in let variadic2 = Type . Variable . Variadic . Tuple . create " Ts2 " in let parameter_variadic = Type ... |
let test_union_upper_bound _ = let assert_union_upper_bound map expected = assert_equal ~ printer : Type . show ~ cmp : Type . equal ( Type . OrderedTypes . union_upper_bound map ) expected in assert_union_upper_bound ( Concrete [ Type . integer ; Type . string ; Type . bool ] ) ( Type . union [ Type . integer ; Type .... |
let test_infer_transform _ = let assert_transform ~ expected ~ annotation = assert_equal ( Type . infer_transform annotation ) expected in assert_transform ~ annotation ( : Type . parametric " _PathLike " [ ! Type . Primitive " string " ] ) ~ expected ( : Type . parametric " PathLike " [ ! Type . Primitive " string " ]... |
let test_fields_from_constructor _ = let assert_fields ~ constructor ~ expected = assert_equal ~ printer [ :% show : Type . t Type . Record . TypedDictionary . typed_dictionary_field list option ] expected ( Type . TypedDictionary . fields_from_constructor constructor ) in let fields = [ { Type . Record . TypedDictiona... |
let test_is_unit_test _ = let assert_is_unit_test name expected = Type . Primitive . is_unit_test name |> assert_equal expected in assert_is_unit_test " unittest . TestCase " true ; assert_is_unit_test " unittest . case . TestCase " true ; assert_is_unit_test " a . TestCase " false ; ( ) |
let polynomial_show_normal = Type . Polynomial . show_normal ~ show_variable : Type . polynomial_show_variable ~ show_type : Type . pp |
let polynomial_add = Type . Polynomial . add ~ compare_t : Type . compare |
let polynomial_subtract = Type . Polynomial . subtract ~ compare_t : Type . compare |
let polynomial_multiply = Type . Polynomial . multiply ~ compare_t : Type . compare |
let polynomial_divide = Type . Polynomial . divide ~ compare_t : Type . compare |
let test_polynomial_create_from_list _ = let assert_create given expected = let given = polynomial_create_from_variables_list given in assert_equal ~ printer : Fn . id expected ( polynomial_show_normal given ) in let x = Type . Variable . Unary . create " x " in let y = Type . Variable . Unary . create " y " in let z =... |
let test_polynomial_to_type _ = let x = Type . Variable . Unary . create " x " in let y = Type . Variable . Unary . create " y " in let aliases ? replace_unbound_parameters_with_any : _ = function | " x " -> Some ( Type . TypeAlias ( Type . Variable x ) ) | " y " -> Some ( Type . TypeAlias ( Type . Variable y ) ) | _ -... |
let test_polynomial_replace _ = let x = Type . Variable . Unary . create " x " in let y = Type . Variable . Unary . create " y " in let z = Type . Variable . Unary . create " z " in let w = Type . Variable . Unary . create " w " in let assert_polynomial_replace given ~ replacements ( : variable , by ) expected = let re... |
let test_add_polynomials _ = let assert_add given1 given2 expected = let given1 = polynomial_create_from_variables_list given1 in let given2 = polynomial_create_from_variables_list given2 in assert_equal ~ printer : Fn . id expected ( polynomial_show_normal ( polynomial_add given1 given2 ) ) ; assert_equal ~ printer : ... |
let test_subtract_polynomials _ = let assert_subtract given1 given2 expected = let given1 = polynomial_create_from_variables_list given1 in let given2 = polynomial_create_from_variables_list given2 in assert_equal ~ printer : Fn . id expected ( polynomial_show_normal ( polynomial_subtract given1 given2 ) ) in let x = T... |
let test_multiply_polynomial _ = let assert_multiply given1 given2 expected = let given1 = polynomial_create_from_variables_list given1 in let given2 = polynomial_create_from_variables_list given2 in assert_equal ~ printer : Fn . id expected ( polynomial_show_normal ( polynomial_multiply given1 given2 ) ) ; assert_equa... |
let test_divide_polynomial _ = let assert_divide given1 given2 expected = let given1 = polynomial_create_from_variables_list given1 in let given2 = polynomial_create_from_variables_list given2 in assert_equal ~ printer : Fn . id expected ( polynomial_show_normal ( polynomial_divide given1 given2 ) ) in let x = Type . V... |
let test_parameter_create _ = assert_equal ( Type . Callable . Parameter . create [ { Type . Callable . Parameter . name = " __ " ; annotation = Type . integer ; default = false } ] ) [ Type . Callable . Parameter . PositionalOnly { index = 0 ; annotation = Type . integer ; default = false } ; ] |
let test_resolve_getitem_callee _ = let open Expression in let assert_resolved_getitem_callee ( ? resolve_aliases = Fn . id ) actual expected = let parse_callee given = match parse_single_expression given |> Node . value with | Expression . Call { callee = { Node . value = callee ; _ } ; _ } -> callee | _ -> failwith "... |
let test_resolve_class _ = let assert_resolved_class annotation expected = assert_equal ~ printer ( : fun x -> [ % sexp_of : Type . class_data list option ] x |> Sexp . to_string_hum ) expected ( Type . resolve_class annotation ) in assert_resolved_class Type . Any ( Some [ ] ) ; assert_resolved_class ( Type . meta Typ... |
let test_show _ = let assert_show given ~ expected_full ~ expected_concise = assert_equal ~ cmp : String . equal ~ printer : Fn . id ( [ % show : Type . t ] given ) expected_full ; assert_equal ~ cmp : String . equal ~ printer : Fn . id ( Type . show_concise given ) expected_concise in let callable1 = Type . Callable .... |
let ( ) = " type " >::: [ " create " >:: test_create ; " create_callable " >:: test_create_callable ; " create_alias " >:: test_create_alias ; " create_type_operator " >:: test_create_type_operator ; " create_variadic_tuple " >:: test_create_variadic_tuple ; " resolve_aliases " >:: test_resolve_aliases ; " instantiate ... |
type error = Unbound_type_variable of string | Undefined_type_constructor of Path . t | Type_arity_mismatch of Longident . t * int * int | Bound_type_variable of string | Recursive_type | Unbound_row_variable of Longident . t | Type_mismatch of Ctype . Unification_trace . t | Alias_type_mismatch of Ctype . Unification_... |
type variable_context = int * type_expr TyVarMap . t |
let transl_modtype_longident = ref ( fun _ -> assert false ) |
let transl_modtype = ref ( fun _ -> assert false ) |
let create_package_mty fake loc env ( p , l ) = let l = List . sort ( fun ( s1 , _t1 ) ( s2 , _t2 ) -> if s1 . txt = s2 . txt then raise ( Error ( loc , env , Multiple_constraints_on_type s1 . txt ) ) ; compare s1 . txt s2 . txt ) l in l , List . fold_left ( fun mty ( s , t ) -> let d = { ptype_name = mkloc ( Longident... |
let type_variables = ref ( TyVarMap . empty : type_expr TyVarMap . t ) |
let univars = ref ( [ ] : ( string * type_expr ) list ) |
let pre_univars = ref ( [ ] : type_expr list ) |
let used_variables = ref ( TyVarMap . empty : ( type_expr * Location . t ) TyVarMap . t ) |
let reset_type_variables ( ) = reset_global_level ( ) ; Ctype . reset_reified_var_counter ( ) ; type_variables := TyVarMap . empty |
let narrow ( ) = ( increase_global_level ( ) , ! type_variables ) |
let widen ( gl , tv ) = restore_global_level gl ; type_variables := tv |
let strict_ident c = ( c = ' _ ' || c >= ' a ' && c <= ' z ' || c >= ' A ' && c <= ' Z ' ) |
let validate_name = function None -> None | Some name as s -> if name <> " " && strict_ident name . [ 0 ] then s else None |
let new_global_var ? name ( ) = new_global_var ? name ( : validate_name name ) ( ) |
let newvar ? name ( ) = newvar ? name ( : validate_name name ) ( ) |
let type_variable loc name = try TyVarMap . find name ! type_variables with Not_found -> raise ( Error ( loc , Env . empty , Unbound_type_variable ( " ' " ^ name ) ) ) |
let valid_tyvar_name name = name <> " " && name . [ 0 ] <> ' _ ' |
let transl_type_param env styp = let loc = styp . ptyp_loc in match styp . ptyp_desc with Ptyp_any -> let ty = new_global_var ~ name " : _ " ( ) in { ctyp_desc = Ttyp_any ; ctyp_type = ty ; ctyp_env = env ; ctyp_loc = loc ; ctyp_attributes = styp . ptyp_attributes ; } | Ptyp_var name -> let ty = try if not ( valid_tyva... |
let transl_type_param env styp = Builtin_attributes . warning_scope styp . ptyp_attributes ( fun ( ) -> transl_type_param env styp ) |
let new_pre_univar ? name ( ) = let v = newvar ? name ( ) in pre_univars := v :: ! pre_univars ; v |
type policy = Fixed | Extensible | Univars |
let rec transl_type env policy styp = Builtin_attributes . warning_scope styp . ptyp_attributes ( fun ( ) -> transl_type_aux env policy styp ) let loc = styp . ptyp_loc in let ctyp ctyp_desc ctyp_type = { ctyp_desc ; ctyp_type ; ctyp_env = env ; ctyp_loc = loc ; ctyp_attributes = styp . ptyp_attributes } in match styp ... |
let rec make_fixed_univars ty = let ty = repr ty in if ty . level >= Btype . lowest_level then begin Btype . mark_type_node ty ; match ty . desc with | Tvariant row -> let row = Btype . row_repr row in let more = Btype . row_more row in if Btype . is_Tunivar more then ty . desc <- Tvariant { row with row_fixed = Some (... |
let make_fixed_univars ty = make_fixed_univars ty ; Btype . unmark_type ty |
let create_package_mty = create_package_mty false |
let globalize_used_variables env fixed = let r = ref [ ] in TyVarMap . iter ( fun name ( ty , loc ) -> let v = new_global_var ( ) in let snap = Btype . snapshot ( ) in if try unify env v ty ; true with _ -> Btype . backtrack snap ; false then try r := ( loc , v , TyVarMap . find name ! type_variables ) :: ! r with Not_... |
let transl_simple_type env fixed styp = univars := [ ] ; used_variables := TyVarMap . empty ; let typ = transl_type env ( if fixed then Fixed else Extensible ) styp in globalize_used_variables env fixed ( ) ; make_fixed_univars typ . ctyp_type ; typ |
let transl_simple_type_univars env styp = univars := [ ] ; used_variables := TyVarMap . empty ; pre_univars := [ ] ; begin_def ( ) ; let typ = transl_type env Univars styp in let new_variables = ! used_variables in used_variables := TyVarMap . empty ; TyVarMap . iter ( fun name p -> if TyVarMap . mem name ! type_variab... |
let transl_simple_type_delayed env styp = univars := [ ] ; used_variables := TyVarMap . empty ; let typ = transl_type env Extensible styp in make_fixed_univars typ . ctyp_type ; ( typ , globalize_used_variables env false ) |
let transl_type_scheme env styp = reset_type_variables ( ) ; begin_def ( ) ; let typ = transl_simple_type env false styp in end_def ( ) ; generalize typ . ctyp_type ; typ |
let report_error env ppf = function | Unbound_type_variable name -> let add_name name _ l = if name = " _ " then l else ( " ' " ^ name ) :: l in let names = TyVarMap . fold add_name ! type_variables [ ] in fprintf ppf " The type variable % s is unbound in this type declaration . @ % a " name did_you_mean ( fun ( ) -> M... |
let ( ) = Location . register_error_of_exn ( function | Error ( loc , env , err ) -> Some ( Location . error_of_printer ~ loc ( report_error env ) err ) | Error_forward err -> Some err | _ -> None ) |
let test_check_bounded_variables context = let assert_type_errors = assert_type_errors ~ context in assert_type_errors { | from typing import TypeVar , Callable TFun = TypeVar ( " TFun " , bound = Callable [ [ int ] , None ] ) def foo ( x : TFun ) -> None : x ( 7 ) } | [ ] ; assert_type_errors { | from typing import Ty... |
let test_check_unbounded_variables context = let assert_type_errors = assert_type_errors ~ context in assert_type_errors { | import typing T = typing . TypeVar ( ' T ' ) def expects_any ( input : object ) -> None : . . . def expects_string ( inut : str ) -> None : . . . def foo ( input : T ) -> None : expects_any ( inp... |
let test_check_variable_bindings context = let assert_type_errors = assert_type_errors ~ context in assert_type_errors { | from builtins import str_to_int import typing T = typing . TypeVar ( ' T ' , bound = int ) def foo ( t : T ) -> None : str_to_int ( t ) } | [ " Incompatible parameter type [ 6 ] : In call ` str_to_... |
let test_unbound_variables context = let assert_type_errors = assert_type_errors ~ context in let assert_default_type_errors = assert_default_type_errors ~ context in assert_type_errors { | def foo ( ) -> None : x = [ ] } | [ " Incomplete type [ 37 ] : Type ` typing . List [ Variable [ _T ] ] ` inferred for ` x ` is in... |
let test_distinguish context = let assert_type_errors = assert_type_errors ~ context in assert_type_errors { | import typing _T1 = typing . TypeVar ( " _T1 " ) _T2 = typing . TypeVar ( " _T2 " ) class C ( typing . Generic [ _T1 ] ) : def pair ( self , a : _T1 , b : _T2 ) -> typing . Tuple [ _T1 , _T2 ] : return ( a , b... |
let test_integer_variables context = assert_type_errors ~ context { | import typing_extensions T = typing_extensions . IntVar ( " T " ) X = typing_extensions . IntVar ( " X " ) def baz ( x : X ) -> X : return x def bop ( x : int ) -> None : pass def foo ( x : T ) -> T : y = x . __add__ ( 5 ) z = baz ( x ) bop ( x ) ret... |
let test_nested_variable_error context = assert_type_errors ~ context { | import typing T1 = typing . TypeVar ( " T1 " ) T2 = typing . TypeVar ( " T2 " , typing . List [ T1 ] , typing . Dict [ str , T1 ] ) } | [ " Invalid type [ 31 ] : Expression ` Variable [ T2 <: [ typing . List [ Variable [ test . T1 ] ] , " ^ " typ... |
let test_single_explicit_error context = assert_type_errors ~ context { | import typing T1 = typing . TypeVar ( " T1 " , int ) } | [ " Invalid type [ 31 ] : TypeVar can ' t have a single explicit constraint . Did you mean ` bound = int ` " ; ? ] ; ( ) |
let test_callable_parameter_variadics context = let assert_type_errors = assert_type_errors ~ context in assert_type_errors { | from typing import Callable , List import pyre_extensions V = pyre_extensions . ParameterSpecification ( " V " ) def f ( x : Callable [ V , int ] ) -> Callable [ V , List [ int ] ] : . . . def... |
let test_user_defined_parameter_specification_classes context = let assert_type_errors = assert_type_errors ~ context in assert_type_errors { | from typing import Callable , ParamSpec TParams = ParamSpec ( " TParams " ) def client ( f : Callable [ TParams , int ] ) -> None : def inner ( * args : TParams . args , ** kwa... |
let test_duplicate_type_variables context = let assert_type_errors = assert_type_errors ~ context in assert_type_errors { | from typing import TypeVar , Generic T = TypeVar ( " T " ) S = TypeVar ( " S " ) class A ( Generic [ T , S , T ] ) : pass } | [ " Duplicate type variables [ 59 ] : Duplicate type variable ` T ` in... |
let test_generic_aliases context = let assert_type_errors = assert_type_errors ~ context in assert_type_errors { | from typing import List MyList = List [ int ] x : MyList reveal_type ( x ) reveal_type ( x [ 0 ] ) } | [ " Revealed type [ - 1 ] : Revealed type for ` x ` is ` List [ int ] ` . " ; " Revealed type [ - 1 ] ... |
let test_recursive_aliases context = let assert_type_errors = assert_type_errors ~ context in assert_type_errors { | from typing import Tuple , Union Tree = Union [ int , Tuple [ " Tree " , " Tree " ] ] x : Tree reveal_type ( x ) } | [ " Revealed type [ - 1 ] : Revealed type for ` x ` is ` test . Tree ( resolves to Uni... |
let test_variadic_tuples context = let assert_type_errors = assert_type_errors ~ context in assert_type_errors { | from typing import Tuple from pyre_extensions import TypeVarTuple , Unpack Ts = TypeVarTuple ( " Ts " ) def foo ( x : Tuple [ int , Unpack [ Ts ] ] ) -> Tuple [ bool , Unpack [ Ts ] ] : . . . def bar ( ) -... |
let test_variadic_classes context = let assert_type_errors = assert_type_errors ~ context in assert_type_errors { | from typing import Generic from pyre_extensions import TypeVarTuple , Unpack Ts = TypeVarTuple ( " Ts " ) class Tensor ( Generic [ Unpack [ Ts ] ] ) : . . . def add_bool ( x : Tensor [ int , Unpack [ Ts ]... |
let test_variadic_callables context = let assert_type_errors = assert_type_errors ~ context in assert_type_errors { | from typing import Callable , Tuple from pyre_extensions import TypeVarTuple , Unpack Ts = TypeVarTuple ( " Ts " ) def make_tuple ( leave_this_out : int , * args : Unpack [ Ts ] , message : str ) -> Tup... |
let ( ) = " typeVariable " >::: [ " check_bounded_variables " >:: test_check_bounded_variables ; " check_unbounded_variables " >:: test_check_unbounded_variables ; " check_variable_bindings " >:: test_check_variable_bindings ; " unbound_variables " >:: test_unbound_variables ; " distinguish " >:: test_distinguish ; " i... |
module Make0 ( X : Named_intf . S0 ) : Typerepable . S with type t := X . t = struct module M = Make_typename . Make0 ( X ) let typerep_of_t = Typerep . Named ( M . named , None ) let typename_of_t = M . typename_of_t end |
module Make1 ( X : Named_intf . S1 ) : Typerepable . S1 with type ' a t := ' a X . t = struct module M = Make_typename . Make1 ( X ) let typerep_of_t of_p1 = Typerep . Named ( M . named of_p1 , None ) let typename_of_t = M . typename_of_t end |
module Make2 ( X : Named_intf . S2 ) : Typerepable . S2 with type ( ' a , ' b ) t := ( ' a , ' b ) X . t = struct module M = Make_typename . Make2 ( X ) let typerep_of_t of_p1 of_p2 = Typerep . Named ( M . named of_p1 of_p2 , None ) let typename_of_t = M . typename_of_t end |
module Make3 ( X : Named_intf . S3 ) : Typerepable . S3 with type ( ' a , ' b , ' c ) t := ( ' a , ' b , ' c ) X . t = struct module M = Make_typename . Make3 ( X ) let typerep_of_t of_p1 of_p2 of_p3 = Typerep . Named ( M . named of_p1 of_p2 of_p3 , None ) let typename_of_t = M . typename_of_t end |
module Make4 ( X : Named_intf . S4 ) : Typerepable . S4 with type ( ' a , ' b , ' c , ' d ) t := ( ' a , ' b , ' c , ' d ) X . t = struct module M = Make_typename . Make4 ( X ) let typerep_of_t of_p1 of_p2 of_p3 of_p4 = Typerep . Named ( M . named of_p1 of_p2 of_p3 of_p4 , None ) ; ; let typename_of_t = M . typename_of... |
module Make5 ( X : Named_intf . S5 ) : Typerepable . S5 with type ( ' a , ' b , ' c , ' d , ' e ) t := ( ' a , ' b , ' c , ' d , ' e ) X . t = struct module M = Make_typename . Make5 ( X ) let typerep_of_t of_p1 of_p2 of_p3 of_p4 of_p5 = Typerep . Named ( M . named of_p1 of_p2 of_p3 of_p4 of_p5 , None ) ; ; let typenam... |
type ' a writer = { size : ' a Size . sizer ; write : ' a Write . writer } |
type ' a reader = { read : ' a Read . reader ; vtag_read : ( int -> ' a ) Read . reader } |
type ' a t = { shape : Shape . t ; writer : ' a writer ; reader : ' a reader } |
type ' a writer0 = ' a writer |
type ' a reader0 = ' a reader |
type ' a t0 = ' a t |
module S1 = struct type ( ' a , ' b ) writer = ' a writer0 -> ' b writer0 type ( ' a , ' b ) reader = ' a reader0 -> ' b reader0 type ( ' a , ' b ) t = ' a t0 -> ' b t0 end |
module S2 = struct type ( ' a , ' b , ' c ) writer = ' a writer0 -> ( ' b , ' c ) S1 . writer type ( ' a , ' b , ' c ) reader = ' a reader0 -> ( ' b , ' c ) S1 . reader type ( ' a , ' b , ' c ) t = ' a t0 -> ( ' b , ' c ) S1 . t end |
module S3 = struct type ( ' a , ' b , ' c , ' d ) writer = ' a writer0 -> ( ' b , ' c , ' d ) S2 . writer type ( ' a , ' b , ' c , ' d ) reader = ' a reader0 -> ( ' b , ' c , ' d ) S2 . reader type ( ' a , ' b , ' c , ' d ) t = ' a t0 -> ( ' b , ' c , ' d ) S2 . t end |
let variant_wrong_type name _buf ~ pos_ref _x = Common . raise_variant_wrong_type name ! pos_ref ; ; |
let bin_writer_unit = { size = Size . bin_size_unit ; write = Write . bin_write_unit } |
let bin_reader_unit = { read = Read . bin_read_unit ; vtag_read = variant_wrong_type " unit " } ; ; |
let bin_unit = { shape = bin_shape_unit ; writer = bin_writer_unit ; reader = bin_reader_unit } ; ; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.