Commit 3f3557b
TypeForm: Early-reject functions and modules in try_parse_as_type_expression()
Add a second fast-rejection filter: a string literal that is an identifier
naming a FuncDef, OverloadedFuncDef, or MypyFile is a function or module, never
a type expression. Reject it before the expensive full-parse block.
On mypy's self-check this rejects 48 of the identifier-string literals that
reach the full-parse block (e.g. builtin functions like "classmethod",
"staticmethod", "hash"; user functions; module names like "platform"), all of
which were failing full parses.
Unlike the Var-value filter, this check is a single isinstance with no expensive
follow-on work, and FuncDef/OverloadedFuncDef/MypyFile are mutually exclusive
with the other early-reject node kinds, so it is freely positionable and its
rejection count is order-independent. It is placed by descending rejection
frequency: after the Var-value filter (~157) and before the placeholder check
(~23), i.e. the final order is
unbound type variable (~951) -> value Var (~157)
-> function/module (~48) -> placeholder (~23)
No companion guard is needed (a function or module name is never a valid type,
so nothing valid is rejected; check-typeform and testsemanal unchanged).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>1 parent 1125b30 commit 3f3557b
1 file changed
Lines changed: 11 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8100 | 8100 | | |
8101 | 8101 | | |
8102 | 8102 | | |
8103 | | - | |
8104 | | - | |
8105 | | - | |
8106 | | - | |
8107 | | - | |
8108 | | - | |
8109 | | - | |
| 8103 | + | |
| 8104 | + | |
| 8105 | + | |
| 8106 | + | |
| 8107 | + | |
| 8108 | + | |
| 8109 | + | |
8110 | 8110 | | |
8111 | 8111 | | |
8112 | 8112 | | |
| |||
8127 | 8127 | | |
8128 | 8128 | | |
8129 | 8129 | | |
| 8130 | + | |
| 8131 | + | |
| 8132 | + | |
| 8133 | + | |
8130 | 8134 | | |
8131 | 8135 | | |
8132 | 8136 | | |
| |||
0 commit comments