| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
The union_fallback path in infer_rvalue_with_fallback_context() was being incorrectly skipped when the rvalue contained a ternary (ConditionalExpr), because ternary expressions increment the binder version just like walrus operators do. This caused valid type narrowing via reassignment to be lost. Replace the binder_version check with an explicit check for AssignmentExpr (walrus) in the expression tree, which is more precise and doesn't falsely trigger on ternary expressions. Fixes python#21273
| Back | FazBrowse Home | New Git URL |
Summary
The union_fallback path in infer_rvalue_with_fallback_context() was being incorrectly skipped when the rvalue contained a ternary (ConditionalExpr), because ternary expressions increment the binder version (via frame_context(can_skip=True, fall_through=0) in visit_conditional_expr) just like walrus operators do.
This caused valid type narrowing via reassignment to be lost. For example:
Fix
Replace the binder_version == self.binder.version check with an explicit check for AssignmentExpr (walrus) in the expression tree. This is more precise and does not falsely trigger on ternary expressions or other constructs that happen to increment the binder version.
The helper method _expr_has_assignment_expr() walks the expression tree to check for the presence of any AssignmentExpr node.
Fixes #21273