fix Conformance: Missing type alias validation #2451#3174
fix Conformance: Missing type alias validation #2451#3174asukaminato0721 wants to merge 8 commits intofacebook:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes missing validation for “implicit type aliases” whose RHS is not a valid annotation/type-expression syntax, ensuring these now error at the annotation use site (conformance #2451). The PR also refactors annotation-syntax validation into a reusable helper and updates conformance baselines.
Changes:
- Refactor annotation syntax validation into
annotation_syntax_problemand reuse it for diagnostics. - Detect invalid implicit type-alias bindings (via
NameAssign) and surfaceInvalidAnnotationat the annotation usage site. - Update tests and third-party conformance expectation/result artifacts to reflect the new diagnostics.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
pyrefly/lib/alt/solve.rs |
Adds reusable annotation-syntax helper and new implicit type-alias syntax validation that reports invalid-annotation at use sites. |
pyrefly/lib/test/type_alias.rs |
Updates the conformance test case to expect the new, more specific annotation-syntax errors. |
conformance/third_party/results.json |
Updates aggregated third-party conformance pass/fail counts. |
conformance/third_party/conformance.result |
Updates per-test expectation summary to reflect aliases_implicit.py now passing. |
conformance/third_party/conformance.exp |
Updates expected diagnostic outputs (messages/kinds) for the affected conformance cases. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
@migeed-z has imported this pull request. If you are a Meta employee, you can view this in D101670073. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Hmmm. I am not sure this approach is the right one. The reason is that something like this: will fail and introduce false positives. The reason is that we are interpreting type(..) as a function call and rejecting it, but we should interpret the type of the value instead. So I think the approach needs to be modified to do that instead. |
d36f325 to
58df9a1
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Diff from mypy_primer, showing the effect of this PR on open source code: pytest-autoprofile (https://gitlab.com/TTsangSC/pytest-autoprofile)
- ERROR src/pytest_autoprofile/_typing.py:81:10-14: Expected a type form, got instance of `TypeVar` [not-a-type]
+ ERROR src/pytest_autoprofile/_typing.py:81:10-14: Function call cannot be used in annotations [invalid-annotation]
mypy (https://github.com/python/mypy)
- ERROR mypyc/test-data/fixtures/typing-full.pyi:76:26-29: Expected a type form, got instance of `object` [not-a-type]
- ERROR mypyc/test-data/fixtures/typing-full.pyi:76:36-39: Expected a type form, got instance of `object` [not-a-type]
- ERROR mypyc/test-data/fixtures/typing-full.pyi:76:50-53: Expected a type form, got instance of `object` [not-a-type]
+ ERROR mypyc/test-data/fixtures/typing-full.pyi:76:26-29: Function call cannot be used in annotations [invalid-annotation]
+ ERROR mypyc/test-data/fixtures/typing-full.pyi:76:36-39: Function call cannot be used in annotations [invalid-annotation]
+ ERROR mypyc/test-data/fixtures/typing-full.pyi:76:50-53: Function call cannot be used in annotations [invalid-annotation]
- ERROR mypyc/test-data/fixtures/typing-full.pyi:92:27-30: Expected a type form, got instance of `object` [not-a-type]
- ERROR mypyc/test-data/fixtures/typing-full.pyi:92:37-40: Expected a type form, got instance of `object` [not-a-type]
- ERROR mypyc/test-data/fixtures/typing-full.pyi:92:51-54: Expected a type form, got instance of `object` [not-a-type]
+ ERROR mypyc/test-data/fixtures/typing-full.pyi:92:27-30: Function call cannot be used in annotations [invalid-annotation]
+ ERROR mypyc/test-data/fixtures/typing-full.pyi:92:37-40: Function call cannot be used in annotations [invalid-annotation]
+ ERROR mypyc/test-data/fixtures/typing-full.pyi:92:51-54: Function call cannot be used in annotations [invalid-annotation]
- ERROR mypyc/test-data/fixtures/typing-full.pyi:113:26-29: Expected a type form, got instance of `object` [not-a-type]
- ERROR mypyc/test-data/fixtures/typing-full.pyi:113:36-39: Expected a type form, got instance of `object` [not-a-type]
- ERROR mypyc/test-data/fixtures/typing-full.pyi:113:50-53: Expected a type form, got instance of `object` [not-a-type]
+ ERROR mypyc/test-data/fixtures/typing-full.pyi:113:26-29: Function call cannot be used in annotations [invalid-annotation]
+ ERROR mypyc/test-data/fixtures/typing-full.pyi:113:36-39: Function call cannot be used in annotations [invalid-annotation]
+ ERROR mypyc/test-data/fixtures/typing-full.pyi:113:50-53: Function call cannot be used in annotations [invalid-annotation]
- ERROR mypyc/test-data/fixtures/typing-full.pyi:131:30-33: Expected a type form, got instance of `object` [not-a-type]
+ ERROR mypyc/test-data/fixtures/typing-full.pyi:131:30-33: Function call cannot be used in annotations [invalid-annotation]
- ERROR mypyc/test-data/fixtures/typing-full.pyi:160:34-37: Expected a type form, got instance of `object` [not-a-type]
- ERROR mypyc/test-data/fixtures/typing-full.pyi:160:50-53: Expected a type form, got instance of `object` [not-a-type]
- ERROR mypyc/test-data/fixtures/typing-full.pyi:160:66-69: Expected a type form, got instance of `object` [not-a-type]
- ERROR mypyc/test-data/fixtures/typing-full.pyi:160:74-77: Expected a type form, got instance of `object` [not-a-type]
+ ERROR mypyc/test-data/fixtures/typing-full.pyi:160:34-37: Function call cannot be used in annotations [invalid-annotation]
+ ERROR mypyc/test-data/fixtures/typing-full.pyi:160:50-53: Function call cannot be used in annotations [invalid-annotation]
+ ERROR mypyc/test-data/fixtures/typing-full.pyi:160:66-69: Function call cannot be used in annotations [invalid-annotation]
+ ERROR mypyc/test-data/fixtures/typing-full.pyi:160:74-77: Function call cannot be used in annotations [invalid-annotation]
- ERROR mypyc/test-data/fixtures/typing-full.pyi:171:29-37: Expected a type form, got instance of `Literal[0]` [not-a-type]
- ERROR mypyc/test-data/fixtures/typing-full.pyi:173:22-30: Expected a type form, got instance of `Literal[0]` [not-a-type]
+ ERROR mypyc/test-data/fixtures/typing-full.pyi:171:29-37: Number literal cannot be used in annotations [invalid-annotation]
+ ERROR mypyc/test-data/fixtures/typing-full.pyi:173:22-30: Number literal cannot be used in annotations [invalid-annotation]
- ERROR mypyc/test-data/fixtures/typing-full.pyi:175:30-38: Expected a type form, got instance of `Literal[0]` [not-a-type]
+ ERROR mypyc/test-data/fixtures/typing-full.pyi:175:30-38: Number literal cannot be used in annotations [invalid-annotation]
paasta (https://github.com/yelp/paasta)
+ ERROR paasta_tools/bounce_lib.py:81:17-39: Function call cannot be used in annotations [invalid-annotation]
+ ERROR paasta_tools/bounce_lib.py:86:6-24: Function call cannot be used in annotations [invalid-annotation]
+ ERROR paasta_tools/bounce_lib.py:110:17-39: Function call cannot be used in annotations [invalid-annotation]
+ ERROR paasta_tools/bounce_lib.py:115:6-24: Function call cannot be used in annotations [invalid-annotation]
+ ERROR paasta_tools/bounce_lib.py:128:17-39: Function call cannot be used in annotations [invalid-annotation]
+ ERROR paasta_tools/bounce_lib.py:133:6-24: Function call cannot be used in annotations [invalid-annotation]
+ ERROR paasta_tools/bounce_lib.py:155:17-39: Function call cannot be used in annotations [invalid-annotation]
+ ERROR paasta_tools/bounce_lib.py:160:6-24: Function call cannot be used in annotations [invalid-annotation]
+ ERROR paasta_tools/bounce_lib.py:173:17-39: Function call cannot be used in annotations [invalid-annotation]
+ ERROR paasta_tools/bounce_lib.py:178:6-24: Function call cannot be used in annotations [invalid-annotation]
+ ERROR paasta_tools/drain_lib.py:263:16-23: Function call cannot be used in annotations [invalid-annotation]
+ ERROR paasta_tools/drain_lib.py:264:24-31: Function call cannot be used in annotations [invalid-annotation]
+ ERROR paasta_tools/drain_lib.py:265:22-29: Function call cannot be used in annotations [invalid-annotation]
+ ERROR paasta_tools/drain_lib.py:266:26-33: Function call cannot be used in annotations [invalid-annotation]
+ ERROR paasta_tools/drain_lib.py:304:45-52: Function call cannot be used in annotations [invalid-annotation]
+ ERROR paasta_tools/frameworks/native_service_config.py:96:14-20: Function call cannot be used in annotations [invalid-annotation]
+ ERROR paasta_tools/frameworks/native_service_config.py:97:15-22: Function call cannot be used in annotations [invalid-annotation]
+ ERROR paasta_tools/frameworks/native_service_config.py:102:16-29: Function call cannot be used in annotations [invalid-annotation]
+ ERROR paasta_tools/frameworks/native_service_config.py:103:14-25: Function call cannot be used in annotations [invalid-annotation]
+ ERROR paasta_tools/generate_deployments_for_service.py:132:18-29: Function call cannot be used in annotations [invalid-annotation]
+ ERROR paasta_tools/generate_deployments_for_service.py:227:77-88: Function call cannot be used in annotations [invalid-annotation]
+ ERROR paasta_tools/generate_deployments_for_service.py:228:6-21: Function call cannot be used in annotations [invalid-annotation]
+ ERROR paasta_tools/hacheck.py:39:40-49: Function call cannot be used in annotations [invalid-annotation]
+ ERROR paasta_tools/hacheck.py:67:19-28: Function call cannot be used in annotations [invalid-annotation]
+ ERROR paasta_tools/kubernetes_tools.py:2346:22-40: Function call cannot be used in annotations [invalid-annotation]
+ ERROR paasta_tools/kubernetes_tools.py:2454:17-30: Function call cannot be used in annotations [invalid-annotation]
+ ERROR paasta_tools/mesos/master.py:301:41-53: Function call cannot be used in annotations [invalid-annotation]
|
Primer Diff Classification❌ 1 regression(s) | ➖ 2 neutral | 3 project(s) total | +45, -18 errors 1 regression(s) across paasta. error kinds:
Detailed analysis❌ Regression (1)paasta (+27)
➖ Neutral (2)pytest-autoprofile (+1, -1)
mypy (+17, -17)
Suggested fixesSummary: The new implicit_alias_call_uses_runtime_type() function doesn't recognize mypy_extensions.TypedDict as a valid TypedDict constructor, causing 27 false-positive invalid-annotation errors in paasta. 1. In the
Was this helpful? React with 👍 or 👎 Classification by primer-classifier (3 LLM) |
|
so... should i also support mypy_extensions.TypedDict ? |
Summary
Fixes #2451
factored the syntax check into a reusable helper.
detect NameAssign bindings that were never real implicit aliases and surface the syntax error at the annotation use site.
preserves normal runtime-value typing while fixing the implicit-alias false negatives.
Test Plan
update test