Skip to content

fix Conformance: Missing type alias validation #2451#3174

Open
asukaminato0721 wants to merge 13 commits intofacebook:mainfrom
asukaminato0721:2451
Open

fix Conformance: Missing type alias validation #2451#3174
asukaminato0721 wants to merge 13 commits intofacebook:mainfrom
asukaminato0721:2451

Conversation

@asukaminato0721
Copy link
Copy Markdown
Contributor

@asukaminato0721 asukaminato0721 commented Apr 18, 2026

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

@meta-cla meta-cla Bot added the cla signed label Apr 18, 2026
@asukaminato0721 asukaminato0721 marked this pull request as ready for review April 18, 2026 08:34
Copilot AI review requested due to automatic review settings April 18, 2026 08:34
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_problem and reuse it for diagnostics.
  • Detect invalid implicit type-alias bindings (via NameAssign) and surface InvalidAnnotation at 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.

Comment thread pyrefly/lib/alt/solve.rs Outdated
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions github-actions Bot added size/l and removed size/l labels Apr 18, 2026
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions github-actions Bot added size/l and removed size/l labels Apr 18, 2026
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@migeed-z migeed-z self-assigned this Apr 20, 2026
@meta-codesync
Copy link
Copy Markdown
Contributor

meta-codesync Bot commented Apr 20, 2026

@migeed-z has imported this pull request. If you are a Meta employee, you can view this in D101670073.

Comment thread pyrefly/lib/alt/solve.rs Outdated
Comment thread pyrefly/lib/test/type_alias.rs
Comment thread pyrefly/lib/test/type_alias.rs
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@migeed-z
Copy link
Copy Markdown
Contributor

Hmmm. I am not sure this approach is the right one. The reason is that something like this:

DynClass = type("DynClass", (), {})
def f(x: DynClass) -> None:  # E: Function call cannot be used in annotations
    pass

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.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread crates/pyrefly_types/src/type_info.rs Outdated
Comment thread pyrefly/lib/alt/solve.rs
Comment on lines +650 to +653
let anon_key = Key::Anon(call.range);
self.bindings()
.key_to_idx_hashed_opt(Hashed::new(&anon_key))
.is_some_and(|idx| matches!(self.bindings().get(idx), Binding::ClassDef(..)))
Copy link

Copilot AI Apr 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

call_has_synthesized_runtime_type duplicates the synthesized_functional_class_type binding lookup logic that already exists on AnswersSolver (pyrefly/lib/alt/expr.rs). Reusing that helper (or factoring the shared logic) would reduce duplication and help keep the anon-key/classdef detection consistent across the codebase.

Suggested change
let anon_key = Key::Anon(call.range);
self.bindings()
.key_to_idx_hashed_opt(Hashed::new(&anon_key))
.is_some_and(|idx| matches!(self.bindings().get(idx), Binding::ClassDef(..)))
self.synthesized_functional_class_type(call.range).is_some()

Copilot uses AI. Check for mistakes.
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions github-actions Bot added size/l and removed size/l labels Apr 23, 2026
@asukaminato0721 asukaminato0721 marked this pull request as ready for review April 23, 2026 23:44
@github-actions
Copy link
Copy Markdown

Diff from mypy_primer, showing the effect of this PR on open source code:

bokeh (https://github.com/bokeh/bokeh)
- ERROR src/bokeh/document/config.pyi:21:19-30: Expected a type form, got instance of `Enumeration` [not-a-type]
+ ERROR src/bokeh/document/config.pyi:21:19-30: Function call cannot be used in annotations [invalid-annotation]

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]

async-utils (https://github.com/mikeshardmind/async-utils)
- ERROR src/async_utils/_as_completed.py:46:34-35: Expected a type form, got instance of `TypeVar` [not-a-type]
+ ERROR src/async_utils/_as_completed.py:46:34-35: Function call cannot be used in annotations [invalid-annotation]
- ERROR src/async_utils/_as_completed.py:58:40-41: Expected a type form, got instance of `TypeVar` [not-a-type]
+ ERROR src/async_utils/_as_completed.py:58:40-41: Function call cannot be used in annotations [invalid-annotation]
- ERROR src/async_utils/_graphs.py:83:30-45: Expected a type form, got instance of `TypeVar` [not-a-type]
- ERROR src/async_utils/_graphs.py:84:20-35: Expected a type form, got instance of `TypeVar` [not-a-type]
+ ERROR src/async_utils/_graphs.py:83:30-45: Function call cannot be used in annotations [invalid-annotation]
+ ERROR src/async_utils/_graphs.py:84:20-35: Function call cannot be used in annotations [invalid-annotation]
- ERROR src/async_utils/_graphs.py:127:38-53: Expected a type form, got instance of `TypeVar` [not-a-type]
- ERROR src/async_utils/_graphs.py:127:70-85: Expected a type form, got instance of `TypeVar` [not-a-type]
+ ERROR src/async_utils/_graphs.py:127:38-53: Function call cannot be used in annotations [invalid-annotation]
+ ERROR src/async_utils/_graphs.py:127:70-85: Function call cannot be used in annotations [invalid-annotation]
- ERROR src/async_utils/_graphs.py:138:36-51: Expected a type form, got instance of `TypeVar` [not-a-type]
- ERROR src/async_utils/_graphs.py:138:66-81: Expected a type form, got instance of `TypeVar` [not-a-type]
+ ERROR src/async_utils/_graphs.py:138:36-51: Function call cannot be used in annotations [invalid-annotation]
+ ERROR src/async_utils/_graphs.py:138:66-81: Function call cannot be used in annotations [invalid-annotation]
- ERROR src/async_utils/lru.py:89:27-28: Expected a type form, got instance of `TypeVar` [not-a-type]
+ ERROR src/async_utils/lru.py:89:27-28: Function call cannot be used in annotations [invalid-annotation]
- ERROR src/async_utils/lru.py:123:32-33: Expected a type form, got instance of `TypeVar` [not-a-type]
- ERROR src/async_utils/lru.py:123:41-42: Expected a type form, got instance of `TypeVar` [not-a-type]
- ERROR src/async_utils/lru.py:127:32-33: Expected a type form, got instance of `TypeVar` [not-a-type]
- ERROR src/async_utils/lru.py:127:42-43: Expected a type form, got instance of `TypeVar` [not-a-type]
- ERROR src/async_utils/lru.py:135:31-32: Expected a type form, got instance of `TypeVar` [not-a-type]
- ERROR src/async_utils/lru.py:135:41-42: Expected a type form, got instance of `TypeVar` [not-a-type]
- ERROR src/async_utils/lru.py:135:50-51: Expected a type form, got instance of `TypeVar` [not-a-type]
- ERROR src/async_utils/lru.py:157:27-28: Expected a type form, got instance of `TypeVar` [not-a-type]
+ ERROR src/async_utils/lru.py:123:32-33: Function call cannot be used in annotations [invalid-annotation]
+ ERROR src/async_utils/lru.py:123:41-42: Function call cannot be used in annotations [invalid-annotation]
+ ERROR src/async_utils/lru.py:127:32-33: Function call cannot be used in annotations [invalid-annotation]
+ ERROR src/async_utils/lru.py:127:42-43: Function call cannot be used in annotations [invalid-annotation]
+ ERROR src/async_utils/lru.py:135:31-32: Function call cannot be used in annotations [invalid-annotation]
+ ERROR src/async_utils/lru.py:135:41-42: Function call cannot be used in annotations [invalid-annotation]
+ ERROR src/async_utils/lru.py:135:50-51: Function call cannot be used in annotations [invalid-annotation]
+ ERROR src/async_utils/lru.py:157:27-28: Function call cannot be used in annotations [invalid-annotation]
- ERROR src/async_utils/lru.py:275:32-33: Expected a type form, got instance of `TypeVar` [not-a-type]
- ERROR src/async_utils/lru.py:275:41-42: Expected a type form, got instance of `TypeVar` [not-a-type]
- ERROR src/async_utils/lru.py:283:32-33: Expected a type form, got instance of `TypeVar` [not-a-type]
- ERROR src/async_utils/lru.py:283:42-43: Expected a type form, got instance of `TypeVar` [not-a-type]
- ERROR src/async_utils/lru.py:295:27-28: Expected a type form, got instance of `TypeVar` [not-a-type]
+ ERROR src/async_utils/lru.py:275:32-33: Function call cannot be used in annotations [invalid-annotation]
+ ERROR src/async_utils/lru.py:275:41-42: Function call cannot be used in annotations [invalid-annotation]
+ ERROR src/async_utils/lru.py:283:32-33: Function call cannot be used in annotations [invalid-annotation]
+ ERROR src/async_utils/lru.py:283:42-43: Function call cannot be used in annotations [invalid-annotation]
+ ERROR src/async_utils/lru.py:295:27-28: Function call cannot be used in annotations [invalid-annotation]
- ERROR src/async_utils/lru.py:319:27-28: Expected a type form, got instance of `TypeVar` [not-a-type]
+ ERROR src/async_utils/lru.py:319:27-28: Function call cannot be used in annotations [invalid-annotation]
- ERROR src/async_utils/scheduler.py:44:51-52: Expected a type form, got instance of `TypeVar` [not-a-type]
- ERROR src/async_utils/scheduler.py:46:23-24: Expected a type form, got instance of `TypeVar` [not-a-type]
+ ERROR src/async_utils/scheduler.py:44:51-52: Function call cannot be used in annotations [invalid-annotation]
+ ERROR src/async_utils/scheduler.py:46:23-24: Function call cannot be used in annotations [invalid-annotation]
- ERROR src/async_utils/scheduler.py:98:34-35: Expected a type form, got instance of `TypeVar` [not-a-type]
- ERROR src/async_utils/scheduler.py:119:60-61: Expected a type form, got instance of `TypeVar` [not-a-type]
+ ERROR src/async_utils/scheduler.py:98:34-35: Function call cannot be used in annotations [invalid-annotation]
+ ERROR src/async_utils/scheduler.py:119:60-61: Function call cannot be used in annotations [invalid-annotation]
- ERROR src/async_utils/waterfall.py:108:25-26: Expected a type form, got instance of `TypeVar` [not-a-type]
+ ERROR src/async_utils/waterfall.py:108:25-26: Function call cannot be used in annotations [invalid-annotation]

mypy (https://github.com/python/mypy)
- ERROR mypy/typeshed/stdlib/typing.pyi:151:14-16: Expected a type form, got instance of `TypeVar` [not-a-type]
- ERROR mypy/typeshed/stdlib/typing.pyi:151:21-23: Expected a type form, got instance of `TypeVar` [not-a-type]
- ERROR mypy/typeshed/stdlib/typing.pyi:383:29-31: Expected a type form, got instance of `TypeVar` [not-a-type]
- ERROR mypy/typeshed/stdlib/typing.pyi:383:39-41: Expected a type form, got instance of `TypeVar` [not-a-type]
+ ERROR mypy/typeshed/stdlib/typing.pyi:151:14-16: Function call cannot be used in annotations [invalid-annotation]
+ ERROR mypy/typeshed/stdlib/typing.pyi:151:21-23: Function call cannot be used in annotations [invalid-annotation]
+ ERROR mypy/typeshed/stdlib/typing.pyi:383:29-31: Function call cannot be used in annotations [invalid-annotation]
+ ERROR mypy/typeshed/stdlib/typing.pyi:383:39-41: Function call cannot be used in annotations [invalid-annotation]
- ERROR mypy/typeshed/stdlib/typing.pyi:410:20-22: Expected a type form, got instance of `TypeVar` [not-a-type]
- ERROR mypy/typeshed/stdlib/typing.pyi:410:27-29: Expected a type form, got instance of `TypeVar` [not-a-type]
- ERROR mypy/typeshed/stdlib/typing.pyi:411:24-26: Expected a type form, got instance of `TypeVar` [not-a-type]
- ERROR mypy/typeshed/stdlib/typing.pyi:411:31-33: Expected a type form, got instance of `TypeVar` [not-a-type]
+ ERROR mypy/typeshed/stdlib/typing.pyi:410:20-22: Function call cannot be used in annotations [invalid-annotation]
+ ERROR mypy/typeshed/stdlib/typing.pyi:410:27-29: Function call cannot be used in annotations [invalid-annotation]
+ ERROR mypy/typeshed/stdlib/typing.pyi:411:24-26: Function call cannot be used in annotations [invalid-annotation]
+ ERROR mypy/typeshed/stdlib/typing.pyi:411:31-33: Function call cannot be used in annotations [invalid-annotation]
- ERROR mypy/typeshed/stdlib/typing.pyi:421:34-37: Expected a type form, got instance of `TypeVar` [not-a-type]
- ERROR mypy/typeshed/stdlib/typing.pyi:421:42-45: Expected a type form, got instance of `TypeVar` [not-a-type]
+ ERROR mypy/typeshed/stdlib/typing.pyi:421:34-37: Function call cannot be used in annotations [invalid-annotation]
+ ERROR mypy/typeshed/stdlib/typing.pyi:421:42-45: Function call cannot be used in annotations [invalid-annotation]
- ERROR mypy/typeshed/stdlib/typing.pyi:466:28-31: Expected a type form, got instance of `TypeVar` [not-a-type]
- ERROR mypy/typeshed/stdlib/typing.pyi:466:36-39: Expected a type form, got instance of `TypeVar` [not-a-type]
+ ERROR mypy/typeshed/stdlib/typing.pyi:466:28-31: Function call cannot be used in annotations [invalid-annotation]
+ ERROR mypy/typeshed/stdlib/typing.pyi:466:36-39: Function call cannot be used in annotations [invalid-annotation]
- ERROR mypy/typeshed/stdlib/typing.pyi:501:26-31: Expected a type form, got instance of `TypeVar` [not-a-type]
+ ERROR mypy/typeshed/stdlib/typing.pyi:501:26-31: Function call cannot be used in annotations [invalid-annotation]
- ERROR mypy/typeshed/stdlib/typing.pyi:511:45-50: Expected a type form, got instance of `TypeVar` [not-a-type]
+ ERROR mypy/typeshed/stdlib/typing.pyi:511:45-50: Function call cannot be used in annotations [invalid-annotation]
- ERROR mypy/typeshed/stdlib/typing.pyi:534:27-32: Expected a type form, got instance of `TypeVar` [not-a-type]
+ ERROR mypy/typeshed/stdlib/typing.pyi:534:27-32: Function call cannot be used in annotations [invalid-annotation]
- ERROR mypy/typeshed/stdlib/typing.pyi:548:27-37: Expected a type form, got instance of `TypeVar` [not-a-type]
- ERROR mypy/typeshed/stdlib/typing.pyi:550:27-40: Expected a type form, got instance of `TypeVar` [not-a-type]
- ERROR mypy/typeshed/stdlib/typing.pyi:550:48-58: Expected a type form, got instance of `TypeVar` [not-a-type]
- ERROR mypy/typeshed/stdlib/typing.pyi:555:10-20: Expected a type form, got instance of `TypeVar` [not-a-type]
- ERROR mypy/typeshed/stdlib/typing.pyi:558:98-108: Expected a type form, got instance of `TypeVar` [not-a-type]
+ ERROR mypy/typeshed/stdlib/typing.pyi:548:27-37: Function call cannot be used in annotations [invalid-annotation]
+ ERROR mypy/typeshed/stdlib/typing.pyi:550:27-40: Function call cannot be used in annotations [invalid-annotation]
+ ERROR mypy/typeshed/stdlib/typing.pyi:550:48-58: Function call cannot be used in annotations [invalid-annotation]
+ ERROR mypy/typeshed/stdlib/typing.pyi:555:10-20: Function call cannot be used in annotations [invalid-annotation]
+ ERROR mypy/typeshed/stdlib/typing.pyi:558:98-108: Function call cannot be used in annotations [invalid-annotation]
- ERROR mypy/typeshed/stdlib/typing.pyi:592:27-43: Expected a type form, got instance of `TypeVar` [not-a-type]
- ERROR mypy/typeshed/stdlib/typing.pyi:592:51-61: Expected a type form, got instance of `TypeVar` [not-a-type]
- ERROR mypy/typeshed/stdlib/typing.pyi:597:10-20: Expected a type form, got instance of `TypeVar` [not-a-type]
- ERROR mypy/typeshed/stdlib/typing.pyi:600:98-108: Expected a type form, got instance of `TypeVar` [not-a-type]
+ ERROR mypy/typeshed/stdlib/typing.pyi:592:27-43: Function call cannot be used in annotations [invalid-annotation]
+ ERROR mypy/typeshed/stdlib/typing.pyi:592:51-61: Function call cannot be used in annotations [invalid-annotation]
+ ERROR mypy/typeshed/stdlib/typing.pyi:597:10-20: Function call cannot be used in annotations [invalid-annotation]
+ ERROR mypy/typeshed/stdlib/typing.pyi:600:98-108: Function call cannot be used in annotations [invalid-annotation]
- ERROR mypy/typeshed/stdlib/typing.pyi:630:28-41: Expected a type form, got instance of `TypeVar` [not-a-type]
+ ERROR mypy/typeshed/stdlib/typing.pyi:630:28-41: Function call cannot be used in annotations [invalid-annotation]
- ERROR mypy/typeshed/stdlib/typing.pyi:658:45-50: Expected a type form, got instance of `TypeVar` [not-a-type]
+ ERROR mypy/typeshed/stdlib/typing.pyi:658:45-50: Function call cannot be used in annotations [invalid-annotation]
- ERROR mypy/typeshed/stdlib/typing.pyi:671:41-43: Expected a type form, got instance of `TypeVar` [not-a-type]
- ERROR mypy/typeshed/stdlib/typing.pyi:674:45-47: Expected a type form, got instance of `TypeVar` [not-a-type]
+ ERROR mypy/typeshed/stdlib/typing.pyi:671:41-43: Function call cannot be used in annotations [invalid-annotation]
+ ERROR mypy/typeshed/stdlib/typing.pyi:674:45-47: Function call cannot be used in annotations [invalid-annotation]
- ERROR mypy/typeshed/stdlib/typing.pyi:680:46-48: Expected a type form, got instance of `TypeVar` [not-a-type]
+ ERROR mypy/typeshed/stdlib/typing.pyi:680:46-48: Function call cannot be used in annotations [invalid-annotation]
- ERROR mypy/typeshed/stdlib/typing.pyi:691:29-31: Expected a type form, got instance of `TypeVar` [not-a-type]
+ ERROR mypy/typeshed/stdlib/typing.pyi:691:29-31: Function call cannot be used in annotations [invalid-annotation]
- ERROR mypy/typeshed/stdlib/typing.pyi:695:42-44: Expected a type form, got instance of `TypeVar` [not-a-type]
- ERROR mypy/typeshed/stdlib/typing.pyi:696:29-31: Expected a type form, got instance of `TypeVar` [not-a-type]
+ ERROR mypy/typeshed/stdlib/typing.pyi:695:42-44: Function call cannot be used in annotations [invalid-annotation]
+ ERROR mypy/typeshed/stdlib/typing.pyi:696:29-31: Function call cannot be used in annotations [invalid-annotation]
- ERROR mypy/typeshed/stdlib/typing.pyi:719:26-28: Expected a type form, got instance of `TypeVar` [not-a-type]
- ERROR mypy/typeshed/stdlib/typing.pyi:721:30-32: Expected a type form, got instance of `TypeVar` [not-a-type]
- ERROR mypy/typeshed/stdlib/typing.pyi:724:22-24: Expected a type form, got instance of `TypeVar` [not-a-type]
- ERROR mypy/typeshed/stdlib/typing.pyi:725:29-31: Expected a type form, got instance of `TypeVar` [not-a-type]
+ ERROR mypy/typeshed/stdlib/typing.pyi:719:26-28: Function call cannot be used in annotations [invalid-annotation]
+ ERROR mypy/typeshed/stdlib/typing.pyi:721:30-32: Function call cannot be used in annotations [invalid-annotation]
+ ERROR mypy/typeshed/stdlib/typing.pyi:724:22-24: Function call cannot be used in annotations [invalid-annotation]
+ ERROR mypy/typeshed/stdlib/typing.pyi:725:29-31: Function call cannot be used in annotations [invalid-annotation]
- ERROR mypy/typeshed/stdlib/typing.pyi:780:32-35: Expected a type form, got instance of `TypeVar` [not-a-type]
- ERROR mypy/typeshed/stdlib/typing.pyi:780:43-49: Expected a type form, got instance of `TypeVar` [not-a-type]
- ERROR mypy/typeshed/stdlib/typing.pyi:783:24-27: Expected a type form, got instance of `TypeVar` [not-a-type]
+ ERROR mypy/typeshed/stdlib/typing.pyi:780:32-35: Function call cannot be used in annotations [invalid-annotation]
+ ERROR mypy/typeshed/stdlib/typing.pyi:780:43-49: Function call cannot be used in annotations [invalid-annotation]
+ ERROR mypy/typeshed/stdlib/typing.pyi:783:24-27: Function call cannot be used in annotations [invalid-annotation]
- ERROR mypy/typeshed/stdlib/typing.pyi:787:24-27: Expected a type form, got instance of `TypeVar` [not-a-type]
- ERROR mypy/typeshed/stdlib/typing.pyi:787:38-40: Expected a type form, got instance of `TypeVar` [not-a-type]
+ ERROR mypy/typeshed/stdlib/typing.pyi:787:24-27: Function call cannot be used in annotations [invalid-annotation]
+ ERROR mypy/typeshed/stdlib/typing.pyi:787:38-40: Function call cannot be used in annotations [invalid-annotation]
- ERROR mypy/typeshed/stdlib/typing.pyi:796:32-35: Expected a type form, got instance of `TypeVar` [not-a-type]
- ERROR mypy/typeshed/stdlib/typing.pyi:796:44-47: Expected a type form, got instance of `TypeVar` [not-a-type]
- ERROR mypy/typeshed/stdlib/typing.pyi:798:32-35: Expected a type form, got instance of `TypeVar` [not-a-type]
- ERROR mypy/typeshed/stdlib/typing.pyi:801:24-27: Expected a type form, got instance of `TypeVar` [not-a-type]
- ERROR mypy/typeshed/stdlib/typing.pyi:801:35-38: Expected a type form, got instance of `TypeVar` [not-a-type]
- ERROR mypy/typeshed/stdlib/typing.pyi:803:24-27: Expected a type form, got instance of `TypeVar` [not-a-type]
- ERROR mypy/typeshed/stdlib/typing.pyi:803:38-41: Expected a type form, got instance of `TypeVar` [not-a-type]
- ERROR mypy/typeshed/stdlib/typing.pyi:803:49-52: Expected a type form, got instance of `TypeVar` [not-a-type]
- ERROR mypy/typeshed/stdlib/typing.pyi:805:24-27: Expected a type form, got instance of `TypeVar` [not-a-type]
- ERROR mypy/typeshed/stdlib/typing.pyi:805:38-40: Expected a type form, got instance of `TypeVar` [not-a-type]
+ ERROR mypy/typeshed/stdlib/typing.pyi:796:32-35: Function call cannot be used in annotations [invalid-annotation]
+ ERROR mypy/typeshed/stdlib/typing.pyi:796:44-47: Function call cannot be used in annotations [invalid-annotation]
+ ERROR mypy/typeshed/stdlib/typing.pyi:798:32-35: Function call cannot be used in annotations [invalid-annotation]
+ ERROR mypy/typeshed/stdlib/typing.pyi:801:24-27: Function call cannot be used in annotations [invalid-annotation]
+ ERROR mypy/typeshed/stdlib/typing.pyi:801:35-38: Function call cannot be used in annotations [invalid-annotation]
+ ERROR mypy/typeshed/stdlib/typing.pyi:803:24-27: Function call cannot be used in annotations [invalid-annotation]
+ ERROR mypy/typeshed/stdlib/typing.pyi:803:38-41: Function call cannot be used in annotations [invalid-annotation]
+ ERROR mypy/typeshed/stdlib/typing.pyi:803:49-52: Function call cannot be used in annotations [invalid-annotation]
+ ERROR mypy/typeshed/stdlib/typing.pyi:805:24-27: Function call cannot be used in annotations [invalid-annotation]
+ ERROR mypy/typeshed/stdlib/typing.pyi:805:38-40: Function call cannot be used in annotations [invalid-annotation]
- ERROR mypy/typeshed/stdlib/typing.pyi:814:63-66: Expected a type form, got instance of `TypeVar` [not-a-type]
+ ERROR mypy/typeshed/stdlib/typing.pyi:814:63-66: Function call cannot be used in annotations [invalid-annotation]
- ERROR mypy/typeshed/stdlib/typing.pyi:816:31-34: Expected a type form, got instance of `TypeVar` [not-a-type]
- ERROR mypy/typeshed/stdlib/typing.pyi:816:45-48: Expected a type form, got instance of `TypeVar` [not-a-type]
- ERROR mypy/typeshed/stdlib/typing.pyi:816:56-59: Expected a type form, got instance of `TypeVar` [not-a-type]
+ ERROR mypy/typeshed/stdlib/typing.pyi:816:31-34: Function call cannot be used in annotations [invalid-annotation]
+ ERROR mypy/typeshed/stdlib/typing.pyi:816:45-48: Function call cannot be used in annotations [invalid-annotation]
+ ERROR mypy/typeshed/stdlib/typing.pyi:816:56-59: Function call cannot be used in annotations [invalid-annotation]
- ERROR mypy/typeshed/stdlib/typing.pyi:840:99-102: Expected a type form, got instance of `TypeVar` [not-a-type]
+ ERROR mypy/typeshed/stdlib/typing.pyi:840:99-102: Function call cannot be used in annotations [invalid-annotation]
- ERROR mypy/typeshed/stdlib/typing.pyi:844:92-95: Expected a type form, got instance of `TypeVar` [not-a-type]
+ ERROR mypy/typeshed/stdlib/typing.pyi:844:92-95: Function call cannot be used in annotations [invalid-annotation]
- ERROR mypy/typeshed/stdlib/typing.pyi:846:62-65: Expected a type form, got instance of `TypeVar` [not-a-type]
+ ERROR mypy/typeshed/stdlib/typing.pyi:846:62-65: Function call cannot be used in annotations [invalid-annotation]
- ERROR mypy/typeshed/stdlib/typing.pyi:877:39-45: Expected a type form, got instance of `TypeVar` [not-a-type]
- ERROR mypy/typeshed/stdlib/typing.pyi:881:47-53: Expected a type form, got instance of `TypeVar` [not-a-type]
+ ERROR mypy/typeshed/stdlib/typing.pyi:877:39-45: Function call cannot be used in annotations [invalid-annotation]
+ ERROR mypy/typeshed/stdlib/typing.pyi:881:47-53: Function call cannot be used in annotations [invalid-annotation]
- ERROR mypy/typeshed/stdlib/typing.pyi:899:24-30: Expected a type form, got instance of `TypeVar` [not-a-type]
+ ERROR mypy/typeshed/stdlib/typing.pyi:899:24-30: Function call cannot be used in annotations [invalid-annotation]
- ERROR mypy/typeshed/stdlib/typing.pyi:907:27-33: Expected a type form, got instance of `TypeVar` [not-a-type]
+ ERROR mypy/typeshed/stdlib/typing.pyi:907:27-33: Function call cannot be used in annotations [invalid-annotation]
- ERROR mypy/typeshed/stdlib/typing.pyi:985:38-40: Expected a type form, got instance of `TypeVar` [not-a-type]
- ERROR mypy/typeshed/stdlib/typing.pyi:992:26-28: Expected a type form, got instance of `TypeVar` [not-a-type]
- ERROR mypy/typeshed/stdlib/typing.pyi:992:36-38: Expected a type form, got instance of `TypeVar` [not-a-type]
- ERROR mypy/typeshed/stdlib/typing.pyi:994:26-28: Expected a type form, got instance of `TypeVar` [not-a-type]
- ERROR mypy/typeshed/stdlib/typing.pyi:994:46-48: Expected a type form, got instance of `TypeVar` [not-a-type]
- ERROR mypy/typeshed/stdlib/typing.pyi:1051:39-41: Expected a type form, got instance of `TypeVar` [not-a-type]
- ERROR mypy/typeshed/stdlib/typing.pyi:1157:26-28: Expected a type form, got instance of `TypeVar` [not-a-type]
- ERROR mypy/typeshed/stdlib/typing.pyi:1157:36-38: Expected a type form, got instance of `TypeVar` [not-a-type]
+ ERROR mypy/typeshed/stdlib/typing.pyi:985:38-40: Function call cannot be used in annotations [invalid-annotation]
+ ERROR mypy/typeshed/stdlib/typing.pyi:992:26-28: Function call cannot be used in annotations [invalid-annotation]
+ ERROR mypy/typeshed/stdlib/typing.pyi:992:36-38: Function call cannot be used in annotations [invalid-annotation]
+ ERROR mypy/typeshed/stdlib/typing.pyi:994:26-28: Function call cannot be used in annotations [invalid-annotation]
+ ERROR mypy/typeshed/stdlib/typing.pyi:994:46-48: Function call cannot be used in annotations [invalid-annotation]
+ ERROR mypy/typeshed/stdlib/typing.pyi:1051:39-41: Function call cannot be used in annotations [invalid-annotation]
+ ERROR mypy/typeshed/stdlib/typing.pyi:1157:26-28: Function call cannot be used in annotations [invalid-annotation]
+ ERROR mypy/typeshed/stdlib/typing.pyi:1157:36-38: Function call cannot be used in annotations [invalid-annotation]
- ERROR mypyc/test-data/fixtures/typing-full.pyi:14:34-37: Expected a type form, got instance of `object` [not-a-type]
- ERROR mypyc/test-data/fixtures/typing-full.pyi:14:42-45: Expected a type form, got instance of `object` [not-a-type]
- ERROR mypyc/test-data/fixtures/typing-full.pyi:16:42-45: Expected a type form, got instance of `object` [not-a-type]
- ERROR mypyc/test-data/fixtures/typing-full.pyi:16:54-57: Expected a type form, got instance of `object` [not-a-type]
- ERROR mypyc/test-data/fixtures/typing-full.pyi:17:29-32: Expected a type form, got instance of `object` [not-a-type]
- ERROR mypyc/test-data/fixtures/typing-full.pyi:17:37-40: Expected a type form, got instance of `object` [not-a-type]
+ ERROR mypyc/test-data/fixtures/typing-full.pyi:14:34-37: Function call cannot be used in annotations [invalid-annotation]
+ ERROR mypyc/test-data/fixtures/typing-full.pyi:14:42-45: Function call cannot be used in annotations [invalid-annotation]
+ ERROR mypyc/test-data/fixtures/typing-full.pyi:16:42-45: Function call cannot be used in annotations [invalid-annotation]
+ ERROR mypyc/test-data/fixtures/typing-full.pyi:16:54-57: Function call cannot be used in annotations [invalid-annotation]
+ ERROR mypyc/test-data/fixtures/typing-full.pyi:17:29-32: Function call cannot be used in annotations [invalid-annotation]
+ ERROR mypyc/test-data/fixtures/typing-full.pyi:17:37-40: Function call cannot be used in annotations [invalid-annotation]
- ERROR mypyc/test-data/fixtures/typing-full.pyi:69:27-31: Expected a type form, got instance of `TypeVar` [not-a-type]
+ ERROR mypyc/test-data/fixtures/typing-full.pyi:69:27-31: Function call cannot be used in annotations [invalid-annotation]
- ERROR mypyc/test-data/fixtures/typing-full.pyi:73:27-28: Expected a type form, got instance of `TypeVar` [not-a-type]
- ERROR mypyc/test-data/fixtures/typing-full.pyi:73:33-34: Expected a type form, got instance of `TypeVar` [not-a-type]
- 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:73:27-28: Function call cannot be used in annotations [invalid-annotation]
+ ERROR mypyc/test-data/fixtures/typing-full.pyi:73:33-34: Function call cannot be used in annotations [invalid-annotation]
+ 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:89:28-29: Expected a type form, got instance of `TypeVar` [not-a-type]
+ ERROR mypyc/test-data/fixtures/typing-full.pyi:89:28-29: 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:110:27-28: Expected a type form, got instance of `TypeVar` [not-a-type]
- ERROR mypyc/test-data/fixtures/typing-full.pyi:110:33-34: Expected a type form, got instance of `TypeVar` [not-a-type]
- 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:110:27-28: Function call cannot be used in annotations [invalid-annotation]
+ ERROR mypyc/test-data/fixtures/typing-full.pyi:110:33-34: Function call cannot be used in annotations [invalid-annotation]
+ 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:38-42: Expected a type form, got instance of `TypeVar` [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:131:38-42: Function call cannot be used in annotations [invalid-annotation]
- ERROR mypyc/test-data/fixtures/typing-full.pyi:135:32-33: Expected a type form, got instance of `TypeVar` [not-a-type]
- ERROR mypyc/test-data/fixtures/typing-full.pyi:135:38-42: Expected a type form, got instance of `TypeVar` [not-a-type]
+ ERROR mypyc/test-data/fixtures/typing-full.pyi:135:32-33: Function call cannot be used in annotations [invalid-annotation]
+ ERROR mypyc/test-data/fixtures/typing-full.pyi:135:38-42: Function call cannot be used in annotations [invalid-annotation]
- ERROR mypyc/test-data/fixtures/typing-full.pyi:137:22-23: Expected a type form, got instance of `TypeVar` [not-a-type]
+ ERROR mypyc/test-data/fixtures/typing-full.pyi:137:22-23: Function call cannot be used in annotations [invalid-annotation]
- ERROR mypyc/test-data/fixtures/typing-full.pyi:139:22-23: Expected a type form, got instance of `TypeVar` [not-a-type]
+ ERROR mypyc/test-data/fixtures/typing-full.pyi:139:22-23: Function call cannot be used in annotations [invalid-annotation]
- ERROR mypyc/test-data/fixtures/typing-full.pyi:146:30-31: Expected a type form, got instance of `TypeVar` [not-a-type]
- ERROR mypyc/test-data/fixtures/typing-full.pyi:146:36-37: Expected a type form, got instance of `TypeVar` [not-a-type]
+ ERROR mypyc/test-data/fixtures/typing-full.pyi:146:30-31: Function call cannot be used in annotations [invalid-annotation]
+ ERROR mypyc/test-data/fixtures/typing-full.pyi:146:36-37: Function call cannot be used in annotations [invalid-annotation]
- ERROR mypyc/test-data/fixtures/typing-full.pyi:154:28-29: Expected a type form, got instance of `TypeVar` [not-a-type]
- ERROR mypyc/test-data/fixtures/typing-full.pyi:154:34-35: Expected a type form, got instance of `TypeVar` [not-a-type]
+ ERROR mypyc/test-data/fixtures/typing-full.pyi:154:28-29: Function call cannot be used in annotations [invalid-annotation]
+ ERROR mypyc/test-data/fixtures/typing-full.pyi:154:34-35: Function call cannot be used in annotations [invalid-annotation]
- ERROR mypyc/test-data/fixtures/typing-full.pyi:158:28-29: Expected a type form, got instance of `TypeVar` [not-a-type]
- 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:169:20-21: Expected a type form, got instance of `TypeVar` [not-a-type]
- ERROR mypyc/test-data/fixtures/typing-full.pyi:169:26-27: Expected a type form, got instance of `TypeVar` [not-a-type]
- 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:173:41-42: Expected a type form, got instance of `TypeVar` [not-a-type]
- ERROR mypyc/test-data/fixtures/typing-full.pyi:174:22-23: Expected a type form, got instance of `TypeVar` [not-a-type]

... (truncated 15 lines) ...

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:227:26-54: Function call cannot be used in annotations [invalid-annotation]
+ ERROR paasta_tools/kubernetes_tools.py:1379:19-47: Function call cannot be used in annotations [invalid-annotation]
+ ERROR paasta_tools/kubernetes_tools.py:1386:17-45: 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]
+ ERROR paasta_tools/metrics/metastatus_lib.py:86:14-26: Function call cannot be used in annotations [invalid-annotation]
+ ERROR paasta_tools/metrics/metastatus_lib.py:122:14-26: Function call cannot be used in annotations [invalid-annotation]
+ ERROR paasta_tools/metrics/metastatus_lib.py:159:14-26: Function call cannot be used in annotations [invalid-annotation]
+ ERROR paasta_tools/metrics/metastatus_lib.py:197:14-26: Function call cannot be used in annotations [invalid-annotation]
+ ERROR paasta_tools/metrics/metastatus_lib.py:434:14-26: Function call cannot be used in annotations [invalid-annotation]
+ ERROR paasta_tools/metrics/metastatus_lib.py:463:14-26: Function call cannot be used in annotations [invalid-annotation]
+ ERROR paasta_tools/metrics/metastatus_lib.py:880:20-32: Function call cannot be used in annotations [invalid-annotation]

@github-actions
Copy link
Copy Markdown

Primer Diff Classification

➖ 5 neutral | 5 project(s) total | +181, -144 errors

Project Verdict Changes Error Kinds Root Cause
bokeh ➖ Neutral +1, -1 invalid-annotation, not-a-type pyrefly/lib/alt/solve.rs
pytest-autoprofile ➖ Neutral +1, -1 TypeVar misclassified as invalid implicit alias classify_name_assign_type_form()
async-utils ➖ Neutral +28, -28 invalid-annotation on TypeVar via module alias classify_name_assign_type_form()
mypy ➖ Neutral +114, -114 invalid-annotation replacing not-a-type on TypeVar usage classify_name_assign_type_form()
paasta ➖ Neutral +37 invalid-annotation classify_name_assign_type_form()
Detailed analysis

➖ Neutral (5)

bokeh (+1, -1)

This is a neutral change in error detection — the same real issue (using a function call result as a type annotation) is being caught, but with a different error kind and message. The old error was not-a-type ('Expected a type form, got instance of Enumeration') and the new error is invalid-annotation ('Function call cannot be used in annotations'). Both are correct — ColorScheme = Enumeration(...) creates a runtime value via a function call, which is not valid annotation syntax per https://typing.readthedocs.io/en/latest/spec/annotations.html. Pyright also flags this (pyright: yes). The new error message is arguably more informative since it explains WHY it's invalid (it's a function call) rather than just saying the result isn't a type form. Net effect: same bug caught, slightly different (arguably better) error message.
Attribution: The change in pyrefly/lib/alt/solve.rs adds the classify_name_assign_type_form method and the check in expr_annotation (around line 5694-5706 in the new code) that detects NameAssignTypeForm::InvalidImplicitAlias and reports ErrorKind::InvalidAnnotation instead of the previous not-a-type error. The Binding::Import handling in binding_to_type_info (line 4418-4421) propagates the NameAssignTypeForm across module boundaries, so when bokeh imports ColorScheme from ..core.enums, the invalid implicit alias information follows. The old code path would have resolved ColorScheme to its runtime type (Enumeration instance) and then reported not-a-type when trying to use it as an annotation. The new code detects the problematic syntax (function call) at the definition site and reports invalid-annotation at the use site.

pytest-autoprofile (+1, -1)

TypeVar misclassified as invalid implicit alias: A TypeVar usage at line 81 was previously reported as not-a-type (TypeVar instance, not a type form) and is now reported as invalid-annotation (Function call cannot be used in annotations). Without seeing the source code, we cannot definitively say which error message is more accurate. If the expression is TypeVar('T') used in an annotation, the new message ('Function call cannot be used in annotations') is a reasonable syntactic description, while the old message described the evaluated result. The PR changed how TypeVar assignments are classified, and this expression is now caught at a different analysis stage. Neither mypy nor pyright flags this line, suggesting the code may be valid and both errors may be false positives. The change in error category represents a shift in how the expression is analyzed rather than a clear regression in accuracy.

Overall: This is a 1-for-1 error swap at the same location. The old error (not-a-type: "Expected a type form, got instance of TypeVar") was replaced by a new error (invalid-annotation: "Function call cannot be used in annotations"). Both are pyrefly-only errors. Without access to the source code at line 81, we cannot definitively assess which error message is more accurate. If the expression at line 81 is something like TypeVar('T') used directly in an annotation, then the new error message ("Function call cannot be used in annotations") is a reasonable description — TypeVar('T') is syntactically a function call. The old error described the runtime result ("got instance of TypeVar"), while the new error describes the syntactic form. The PR added logic to treat TypeVar assignments as RuntimeTypeValue, and the change in error classification suggests the expression is now being caught at a different stage of analysis — as a function call in annotation context rather than being evaluated and then rejected as a TypeVar instance. Since neither mypy nor pyright flags this line, the underlying code may be valid Python, meaning both the old and new errors could be false positives. The net error count is unchanged (1 removed, 1 added). Whether this represents a regression or improvement in error quality depends on the actual source code, which is not available for verification.

Attribution: The PR changes in pyrefly/lib/alt/solve.rs introduce classify_name_assign_type_form() which classifies name assignments as either RuntimeTypeValue (for TypeVar, ParamSpec, TypeVarTuple, and calls to type() or synthesized runtime types) or InvalidImplicitAlias with the syntax problem description. The new annotation_name_assign_type_form() method then checks at annotation use sites whether the name was classified as an invalid implicit alias. The key issue is that when a TypeVar is imported from another module and used in an annotation, the classify_name_assign_type_form method should return RuntimeTypeValue for TypeVar types. But the error message says "Function call" — this suggests the TypeVar at line 81 might be created via a function call pattern that isn't being recognized as a TypeVar by the new classification logic. The PR's test test_typevar_not_treated_as_bad_implicit_alias specifically tests imported TypeVars, suggesting this was a known concern. The fact that this project still gets the error suggests the classification isn't working correctly for this particular case.

async-utils (+28, -28)

invalid-annotation on TypeVar via module alias: All 28 new errors flag T (a TypeVar created via from . import _typings as t; T = t.TypeVar('T')) used in return/parameter annotations. The specific error message is 'Function call cannot be used in annotations', which is triggered because (1) from __future__ import annotations is present (PEP 563), and (2) pyrefly fails to recognize t.TypeVar('T') as a TypeVar declaration due to the module-aliased import path, instead treating T as the result of a function call. This is standard Python typing and these are false positives — regression.
Removed not-a-type on TypeVar: All 28 removed errors were Expected a type form, got instance of TypeVar — TypeVar IS a valid type form when used in annotations. These were false positives, so removing them is an improvement.

Overall: This is a swap of one false positive for another. The old not-a-type errors on TypeVar were wrong, and the new invalid-annotation errors on TypeVar are also wrong. T = t.TypeVar('T') followed by def f(x: T) -> T: is completely standard Python typing. The net effect is neutral-to-regression: the error count is unchanged (28 removed, 28 added), and the new errors are still false positives on valid code.

The specific mechanism: all affected files have from __future__ import annotations, which makes annotations stringified (PEP 563). The TypeVar is created via a module alias (from . import _typings as t; T = t.TypeVar('T')). Because pyrefly's special-case recognition of TypeVar in classify_name_assign_type_form doesn't fire for the module-aliased import path t.TypeVar(...), pyrefly treats T as the result of a plain function call. When T then appears in annotations under PEP 563, pyrefly reports 'Function call cannot be used in annotations' — the specific invalid-annotation message seen in the errors.

Attribution: The classify_name_assign_type_form() method in pyrefly/lib/alt/solve.rs has a special case for Type::TypeVar to return RuntimeTypeValue, but when TypeVar is imported through a module alias (from . import _typings as t; T = t.TypeVar('T')), the type may not resolve to Type::TypeVar by the time classification runs, causing it to fall through to InvalidImplicitAlias. The Binding::Import handling in binding_to_type_info (also in solve.rs) propagates the NameAssignTypeForm from the source module, but the TypeVar special-casing happens at the definition site where the type might not yet be fully resolved.

mypy (+114, -114)

invalid-annotation replacing not-a-type on TypeVar usage: 114 not-a-type errors removed and 114 invalid-annotation errors added at the exact same locations in typing.pyi and typing-full.pyi. Both old and new errors are false positives - they flag valid TypeVar usage like _T in def final(f: _T) -> _T. The error message changed from 'Expected a type form, got instance of TypeVar' to 'Function call cannot be used in annotations', but neither is correct. The PR's TypeVar exemption doesn't work for typing.pyi where TypeVar is defined as a local class. This is a lateral move - same number of false positives, different wording.

Overall: This is a neutral change overall - the error kind changed from not-a-type to invalid-annotation but the same locations are flagged. Both the old and new errors are false positives on valid TypeVar usage in typeshed's typing.pyi. The old errors said 'Expected a type form, got instance of TypeVar' and the new errors say 'Function call cannot be used in annotations'. Neither is correct - _T is a TypeVar and is a perfectly valid type form in annotations. The PR intended to fix this (the test test_typevar_not_treated_as_bad_implicit_alias shows the intent), but the fix doesn't work for the specific case in typing.pyi where TypeVar is defined locally as a class rather than imported from typing. In typing.pyi, TypeVar is defined as class TypeVar: (line 153), so _T = TypeVar("_T") on line 397 is a call to this local class. The PR's classify_name_assign_type_form checks Type::TypeVar(_) but the resolved type of _T in this context might not be recognized as a TypeVar since it's constructed from the locally-defined TypeVar class. The net effect is 114 errors replaced by 114 errors at the same locations - same false positive count, just different error messages.

Attribution: The PR changes in pyrefly/lib/alt/solve.rs introduce classify_name_assign_type_form() which now explicitly checks for Type::TypeVar(_) | Type::ParamSpec(_) | Type::TypeVarTuple(_) and returns NameAssignTypeForm::RuntimeTypeValue for them, meaning they are treated as valid type forms rather than invalid implicit aliases. This fixes the old false positives. However, the new annotation_syntax_problem() function and the reports_implicit_alias_syntax_at_use_site() check in expr_type_form_inner() now surface invalid-annotation errors for names that were classified as InvalidImplicitAlias. The new errors in typing.pyi appear to be cases where the PR's heuristic incorrectly classifies some valid patterns as invalid implicit aliases. Looking at the specific errors: line 151 has def final(f: _T) -> _T - the _T references are to _T = TypeVar("_T") defined on line 397. Since TypeVars are explicitly handled as RuntimeTypeValue, these should NOT produce errors. The errors must be coming from a different mechanism. Looking more carefully at the error locations: line 151:14-16 and 151:21-23 correspond to the _T in def final(f: _T) -> _T. But _T is defined later on line 397. This is a forward reference issue in the stub file. The PR's new logic in annotation_name_assign_type_form() looks up the binding for the name and checks its name_assign_type_form. Since _T is defined later, the binding resolution might be finding a different state. Actually, looking at the error message 'Function call cannot be used in annotations' - this suggests pyrefly is seeing TypeVar("_T") as a function call and flagging it. But the PR explicitly handles TypeVar as RuntimeTypeValue. The issue might be that at line 151, _T hasn't been defined yet (it's defined at line 397), so the lookup might not find the TypeVar classification. Wait - in .pyi files, order shouldn't matter for name resolution. The PR's classify_name_assign_type_form checks the type of the resolved value. If _T resolves to a TypeVar, it should be classified as RuntimeTypeValue. The 114 new errors replacing 114 old errors suggests the error kind changed but the underlying issue (pyrefly not properly handling TypeVar references in this stub) persists.

paasta (+37)

These errors are likely true positives that are consistent with pyright's behavior. The cross-check data (0/37 in mypy, 37/37 in pyright) shows that only mypy accepts these constructs, which makes sense since mypy_extensions is specifically designed for mypy. mypy_extensions.TypedDict is not recognized by pyright or pyrefly as a valid TypedDict form in annotations - both type checkers only recognize typing.TypedDict and typing_extensions.TypedDict. Similarly, Arg and DefaultArg from mypy_extensions are mypy-specific callable argument specifiers that are not part of the typing specification and are not recognized by other type checkers. While the code is valid Python that mypy understands, pyrefly's behavior here is consistent with pyright and reflects a deliberate choice to only support standard typing constructs. Users of pyrefly should migrate to typing.TypedDict (or typing_extensions.TypedDict) and use standard Callable signatures or Protocol classes instead of Arg/DefaultArg.
Attribution: The change to classify_name_assign_type_form() in pyrefly/lib/alt/solve.rs introduces the new classification logic. The call_has_synthesized_runtime_type() method checks if the call range maps to a Binding::ClassDef, and callable_is_builtin_type() checks for builtins.type. Neither check recognizes mypy_extensions.TypedDict as producing a valid type, so these functional TypedDict definitions fall through to InvalidImplicitAlias, causing false positive invalid-annotation errors at every use site.


Was this helpful? React with 👍 or 👎

Classification by primer-classifier (5 LLM)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Conformance: Missing type alias validation

3 participants