- 
          
 - 
                Notifications
    
You must be signed in to change notification settings  - Fork 3k
 
PEP 702 (@deprecated): handle "combined" overloads #19626
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
5c880df
              b2f50ff
              f7b689c
              16c768f
              ee9bd9d
              File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| 
          
            
          
           | 
    @@ -2746,7 +2746,8 @@ def check_overload_call( | |
| # Record if we succeeded. Next we need to see if maybe normal procedure | ||
| # gives a narrower type. | ||
| if unioned_return: | ||
| returns, inferred_types = zip(*unioned_return) | ||
| returns = tuple(u[0] for u in unioned_return) | ||
| inferred_types = tuple(u[1] for u in unioned_return) | ||
| # Note that we use `combine_function_signatures` instead of just returning | ||
| # a union of inferred callables because for example a call | ||
| # Union[int -> int, str -> str](Union[int, str]) is invalid and | ||
| 
        
          
        
         | 
    @@ -2767,19 +2768,25 @@ def check_overload_call( | |
| object_type, | ||
| context, | ||
| ) | ||
| # If any of checks succeed, stop early. | ||
| # If any of checks succeed, perform deprecation tests and stop early. | ||
| if inferred_result is not None and unioned_result is not None: | ||
| # Both unioned and direct checks succeeded, choose the more precise type. | ||
| if ( | ||
| is_subtype(inferred_result[0], unioned_result[0]) | ||
| and not isinstance(get_proper_type(inferred_result[0]), AnyType) | ||
| and not none_type_var_overlap | ||
| ): | ||
| return inferred_result | ||
| return unioned_result | ||
| elif unioned_result is not None: | ||
| unioned_result = None | ||
| else: | ||
| inferred_result = None | ||
| if unioned_result is not None: | ||
| for inferred_type in inferred_types: | ||
                
       | 
||
| if isinstance(c := get_proper_type(inferred_type), CallableType): | ||
| self.chk.warn_deprecated(c.definition, context) | ||
| return unioned_result | ||
| elif inferred_result is not None: | ||
| if inferred_result is not None: | ||
| if isinstance(c := get_proper_type(inferred_result[1]), CallableType): | ||
| self.chk.warn_deprecated(c.definition, context) | ||
| return inferred_result | ||
| 
     | 
||
| # Step 4: Failure. At this point, we know there is no match. We fall back to trying | ||
| 
          
            
          
           | 
    @@ -2933,8 +2940,6 @@ def infer_overload_return_type( | |
| # check for ambiguity due to 'Any' below. | ||
| if not args_contain_any: | ||
| self.chk.store_types(m) | ||
| if isinstance(infer_type, ProperType) and isinstance(infer_type, CallableType): | ||
| self.chk.warn_deprecated(infer_type.definition, context) | ||
| return ret_type, infer_type | ||
| p_infer_type = get_proper_type(infer_type) | ||
| if isinstance(p_infer_type, CallableType): | ||
| 
          
            
          
           | 
    @@ -2971,11 +2976,6 @@ def infer_overload_return_type( | |
| else: | ||
| # Success! No ambiguity; return the first match. | ||
| self.chk.store_types(type_maps[0]) | ||
| inferred_callable = inferred_types[0] | ||
| if isinstance(inferred_callable, ProperType) and isinstance( | ||
| inferred_callable, CallableType | ||
| ): | ||
| self.chk.warn_deprecated(inferred_callable.definition, context) | ||
| return return_types[0], inferred_types[0] | ||
| 
     | 
||
| def overload_erased_call_targets( | ||
| 
          
            
          
           | 
    ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you should use regular list comprehensions for these, not
tuple(...), they are converted to lists few lines below anyway (and then you can remove thelist(...)call below).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems I wanted to stick to the functionality of
zipas close as possible, which is, in fact, not necessary. I changed it.