@@ -2169,6 +2169,7 @@ class CallableType(FunctionLike):
21692169 "from_type_type" , # Was this callable generated by analyzing Type[...]
21702170 # instantiation?
21712171 "is_bound" , # Is this a bound method?
2172+ "original_self_type" , # If bound, what was the type of `self` before?
21722173 "type_guard" , # T, if -> TypeGuard[T] (ret_type is bool in this case).
21732174 "type_is" , # T, if -> TypeIs[T] (ret_type is bool in this case).
21742175 "from_concatenate" , # whether this callable is from a concatenate object
@@ -2195,6 +2196,7 @@ def __init__(
21952196 special_sig : str | None = None ,
21962197 from_type_type : bool = False ,
21972198 is_bound : bool = False ,
2199+ original_self_type : Type | None = None ,
21982200 type_guard : Type | None = None ,
21992201 type_is : Type | None = None ,
22002202 from_concatenate : bool = False ,
@@ -2232,6 +2234,7 @@ def __init__(
22322234 self .from_concatenate = from_concatenate
22332235 self .imprecise_arg_kinds = imprecise_arg_kinds
22342236 self .is_bound = is_bound
2237+ self .original_self_type = original_self_type
22352238 self .type_guard = type_guard
22362239 self .type_is = type_is
22372240 self .unpack_kwargs = unpack_kwargs
@@ -2253,6 +2256,7 @@ def copy_modified(
22532256 special_sig : Bogus [str | None ] = _dummy ,
22542257 from_type_type : Bogus [bool ] = _dummy ,
22552258 is_bound : Bogus [bool ] = _dummy ,
2259+ original_self_type : Bogus [Type | None ] = _dummy ,
22562260 type_guard : Bogus [Type | None ] = _dummy ,
22572261 type_is : Bogus [Type | None ] = _dummy ,
22582262 from_concatenate : Bogus [bool ] = _dummy ,
@@ -2277,6 +2281,9 @@ def copy_modified(
22772281 special_sig = special_sig if special_sig is not _dummy else self .special_sig ,
22782282 from_type_type = from_type_type if from_type_type is not _dummy else self .from_type_type ,
22792283 is_bound = is_bound if is_bound is not _dummy else self .is_bound ,
2284+ original_self_type = (
2285+ original_self_type if original_self_type is not _dummy else self .original_self_type
2286+ ),
22802287 type_guard = type_guard if type_guard is not _dummy else self .type_guard ,
22812288 type_is = type_is if type_is is not _dummy else self .type_is ,
22822289 from_concatenate = (
@@ -2598,6 +2605,11 @@ def serialize(self) -> JsonDict:
25982605 "is_ellipsis_args" : self .is_ellipsis_args ,
25992606 "implicit" : self .implicit ,
26002607 "is_bound" : self .is_bound ,
2608+ "original_self_type" : (
2609+ self .original_self_type .serialize ()
2610+ if self .original_self_type is not None
2611+ else None
2612+ ),
26012613 "type_guard" : self .type_guard .serialize () if self .type_guard is not None else None ,
26022614 "type_is" : (self .type_is .serialize () if self .type_is is not None else None ),
26032615 "from_concatenate" : self .from_concatenate ,
@@ -2620,6 +2632,11 @@ def deserialize(cls, data: JsonDict) -> CallableType:
26202632 is_ellipsis_args = data ["is_ellipsis_args" ],
26212633 implicit = data ["implicit" ],
26222634 is_bound = data ["is_bound" ],
2635+ original_self_type = (
2636+ deserialize_type (data ["original_self_type" ])
2637+ if data ["original_self_type" ] is not None
2638+ else None
2639+ ),
26232640 type_guard = (
26242641 deserialize_type (data ["type_guard" ]) if data ["type_guard" ] is not None else None
26252642 ),
@@ -2641,6 +2658,7 @@ def write(self, data: Buffer) -> None:
26412658 write_bool (data , self .is_ellipsis_args )
26422659 write_bool (data , self .implicit )
26432660 write_bool (data , self .is_bound )
2661+ write_type_opt (data , self .original_self_type )
26442662 write_type_opt (data , self .type_guard )
26452663 write_type_opt (data , self .type_is )
26462664 write_bool (data , self .from_concatenate )
@@ -2663,6 +2681,7 @@ def read(cls, data: Buffer) -> CallableType:
26632681 is_ellipsis_args = read_bool (data ),
26642682 implicit = read_bool (data ),
26652683 is_bound = read_bool (data ),
2684+ original_self_type = read_type_opt (data ),
26662685 type_guard = read_type_opt (data ),
26672686 type_is = read_type_opt (data ),
26682687 from_concatenate = read_bool (data ),
0 commit comments