- 
          
 - 
                Notifications
    
You must be signed in to change notification settings  - Fork 3k
 
          Fix --strict-equality for iteratively visited code
          #19635
        
          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
base: master
Are you sure you want to change the base?
Changes from 8 commits
99725c9
              016eda6
              2182e5d
              edf63d7
              6c3b489
              ab4d567
              9842064
              1d69935
              d3b9ebd
              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 | 
|---|---|---|
| 
          
            
          
           | 
    @@ -1624,6 +1624,21 @@ def incompatible_typevar_value( | |
| ) | ||
| 
     | 
||
| def dangerous_comparison(self, left: Type, right: Type, kind: str, ctx: Context) -> None: | ||
| 
     | 
||
                
      
                  tyralla marked this conversation as resolved.
               
              
                Outdated
          
            Show resolved
            Hide resolved
         | 
||
| # In loops (and similar cases), the same expression might be analysed multiple | ||
| # times and thereby confronted with different types. We only want to raise a | ||
| # `comparison-overlap` error if it occurs in all cases and therefore collect the | ||
| # respective types of the current iteration here so that we can report the error | ||
| # later if it is persistent over all iteration steps: | ||
| for watcher in self.errors.get_watchers(): | ||
| if watcher._filter: | ||
| 
         There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you move this logic into the watcher itself? This access to private followed by special-casing on watcher type is a bit painful to read, IMO this would be clearer as for watcher in self.errors.get_watchers():
    if watcher.store_nonoverlapping_types(ctx, kind, left, right):
        returnWhere  There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ough, you really need both  There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need to excuse. I am obviously using things a little differently from how they were originally intended. Hence, I highly appreciate any thoughts on improving readability.  | 
||
| break | ||
| if isinstance(watcher, IterationErrorWatcher): | ||
| watcher.iteration_dependent_errors.nonoverlapping_types[-1][ | ||
| (ctx.line, ctx.column, ctx.end_line, ctx.end_column, kind) | ||
| ] = (left, right) | ||
| return | ||
| 
     | 
||
| left_str = "element" if kind == "container" else "left operand" | ||
| right_str = "container item" if kind == "container" else "right operand" | ||
| message = "Non-overlapping {} check ({} type: {}, {} type: {})" | ||
| 
          
            
          
           | 
    @@ -2514,8 +2529,11 @@ def match_statement_inexhaustive_match(self, typ: Type, context: Context) -> Non | |
| def iteration_dependent_errors(self, iter_errors: IterationDependentErrors) -> None: | ||
| for error_info in iter_errors.yield_uselessness_error_infos(): | ||
| self.fail(*error_info[:2], code=error_info[2]) | ||
| msu = mypy.typeops.make_simplified_union | ||
| for nonoverlaps, kind, context in iter_errors.yield_nonoverlapping_types(): | ||
| self.dangerous_comparison(msu(nonoverlaps[0]), msu(nonoverlaps[1]), kind, context) | ||
| for types, context in iter_errors.yield_revealed_type_infos(): | ||
| self.reveal_type(mypy.typeops.make_simplified_union(types), context) | ||
| self.reveal_type(msu(types), context) | ||
| 
     | 
||
| 
     | 
||
| def quote_type_string(type_string: str) -> str: | ||
| 
          
            
          
           | 
    ||
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.
Maybe NamedTuple or at least TypeAlias? I'm personally lost in brackets here
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.
In my opinion, TypeAlias doesn't help much. But using NamedTuple (here and in the similar cases above) would definitely increase readability. I will adjust it if there are no performance concerns.