61
61
)
62
62
from .typevar import resolve_bounds_map
63
63
from .value import (
64
+ SelfT ,
64
65
annotate_value ,
65
66
AnnotatedValue ,
66
67
AnySource ,
@@ -1453,6 +1454,7 @@ def can_assign(
1453
1454
if their_ellipsis is not None :
1454
1455
args_annotation = kwargs_annotation = AnyValue (AnySource .ellipsis_callable )
1455
1456
consumed_positional = set ()
1457
+ consumed_required_pos_only = set ()
1456
1458
consumed_keyword = set ()
1457
1459
consumed_paramspec = False
1458
1460
for i , my_param in enumerate (self .parameters .values ()):
@@ -1479,6 +1481,8 @@ def can_assign(
1479
1481
)
1480
1482
tv_maps .append (tv_map )
1481
1483
consumed_positional .add (their_params [i ].name )
1484
+ if their_params [i ].default is None :
1485
+ consumed_required_pos_only .add (their_params [i ].name )
1482
1486
elif args_annotation is not None :
1483
1487
new_tv_maps = can_assign_var_positional (
1484
1488
my_param , args_annotation , i - their_args_index , ctx
@@ -1608,6 +1612,7 @@ def can_assign(
1608
1612
if param .name not in consumed_keyword
1609
1613
and param .kind
1610
1614
in (ParameterKind .KEYWORD_ONLY , ParameterKind .POSITIONAL_OR_KEYWORD )
1615
+ and param .name not in consumed_required_pos_only
1611
1616
]
1612
1617
for extra_param in extra_keyword :
1613
1618
tv_map = extra_param .get_annotation ().can_assign (my_annotation , ctx )
@@ -1885,6 +1890,7 @@ def bind_self(
1885
1890
self ,
1886
1891
* ,
1887
1892
preserve_impl : bool = False ,
1893
+ self_annotation_value : Optional [Value ] = None ,
1888
1894
self_value : Optional [Value ] = None ,
1889
1895
ctx : CanAssignContext ,
1890
1896
) -> Optional ["Signature" ]:
@@ -1910,12 +1916,14 @@ def bind_self(
1910
1916
self_annotation = params [0 ].annotation
1911
1917
else :
1912
1918
return None
1913
- if self_value is not None :
1914
- tv_map = get_tv_map (self_annotation , self_value , ctx )
1919
+ if self_annotation_value is not None :
1920
+ tv_map = get_tv_map (self_annotation , self_annotation_value , ctx )
1915
1921
if isinstance (tv_map , CanAssignError ):
1916
1922
return None
1917
1923
else :
1918
1924
tv_map = {}
1925
+ if self_value is not None :
1926
+ tv_map = {** tv_map , SelfT : self_value }
1919
1927
if tv_map :
1920
1928
new_params = {
1921
1929
param .name : param .substitute_typevars (tv_map ) for param in new_params
@@ -2414,10 +2422,16 @@ def bind_self(
2414
2422
* ,
2415
2423
preserve_impl : bool = False ,
2416
2424
self_value : Optional [Value ] = None ,
2425
+ self_annotation_value : Optional [Value ] = None ,
2417
2426
ctx : CanAssignContext ,
2418
2427
) -> Optional ["ConcreteSignature" ]:
2419
2428
bound_sigs = [
2420
- sig .bind_self (preserve_impl = preserve_impl , self_value = self_value , ctx = ctx )
2429
+ sig .bind_self (
2430
+ preserve_impl = preserve_impl ,
2431
+ self_value = self_value ,
2432
+ self_annotation_value = self_annotation_value ,
2433
+ ctx = ctx ,
2434
+ )
2421
2435
for sig in self .signatures
2422
2436
]
2423
2437
bound_sigs = [sig for sig in bound_sigs if isinstance (sig , Signature )]
@@ -2496,10 +2510,19 @@ def check_call(
2496
2510
return ret
2497
2511
2498
2512
def get_signature (
2499
- self , * , preserve_impl : bool = False , ctx : CanAssignContext
2513
+ self ,
2514
+ * ,
2515
+ preserve_impl : bool = False ,
2516
+ ctx : CanAssignContext ,
2517
+ self_annotation_value : Optional [Value ] = None ,
2500
2518
) -> Optional [ConcreteSignature ]:
2519
+ if self_annotation_value is None :
2520
+ self_annotation_value = self .self_composite .value
2501
2521
return self .signature .bind_self (
2502
- preserve_impl = preserve_impl , self_value = self .self_composite .value , ctx = ctx
2522
+ preserve_impl = preserve_impl ,
2523
+ self_value = self .self_composite .value ,
2524
+ ctx = ctx ,
2525
+ self_annotation_value = self_annotation_value ,
2503
2526
)
2504
2527
2505
2528
def has_return_value (self ) -> bool :
0 commit comments