Commit dbc5c06
Fix false unknown-name error for Literal imported via try/except
Summary:
When `Literal` is imported via a `try/except` block (e.g. `from typing import Literal` in try, `from typing_extensions import Literal` in except), the flow merge produces `FlowStyle::Other` because the two imports come from different modules. This caused `as_special_export()` to fail to recognize `Literal` as a special form, so strings inside `Literal["test"]` were treated as forward references, producing spurious `unknown-name` errors.
The fix adds handling for `Binding::Import` and `Binding::Phi` in `special_export_from_binding_idx`. For Phi nodes (merged try/except branches), all branches are checked recursively and the result is returned if they agree on the same `SpecialExport`.
fixes #2407
Reviewed By: stroxler
Differential Revision: D93287592
fbshipit-source-id: 86ccc87f40155860870a2132a6a41cd9d8a550d01 parent 4fb7136 commit dbc5c06
2 files changed
+40
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
983 | 983 | | |
984 | 984 | | |
985 | 985 | | |
| 986 | + | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
| 990 | + | |
| 991 | + | |
| 992 | + | |
| 993 | + | |
| 994 | + | |
| 995 | + | |
| 996 | + | |
| 997 | + | |
| 998 | + | |
| 999 | + | |
| 1000 | + | |
| 1001 | + | |
| 1002 | + | |
| 1003 | + | |
| 1004 | + | |
| 1005 | + | |
| 1006 | + | |
| 1007 | + | |
986 | 1008 | | |
987 | 1009 | | |
988 | 1010 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
403 | 403 | | |
404 | 404 | | |
405 | 405 | | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
0 commit comments