Skip to content

[ty] Reject type[Callable] special form - #23753

Merged
charliermarsh merged 1 commit into
mainfrom
charlie/type-callable
Mar 6, 2026
Merged

[ty] Reject type[Callable] special form#23753
charliermarsh merged 1 commit into
mainfrom
charlie/type-callable

Conversation

@charliermarsh

@charliermarsh charliermarsh commented Mar 6, 2026

Copy link
Copy Markdown
Member

Summary

The typing spec says:

Any other special forms like Callable are not allowed as an argument to type.

We already reject Generic and TypedDict. We should probably also reject Literal. But this PR adds Callable.

Closes astral-sh/ty#2964.

@charliermarsh charliermarsh added the ty Multi-file analysis & type inference label Mar 6, 2026
@astral-sh-bot

astral-sh-bot Bot commented Mar 6, 2026

Copy link
Copy Markdown

Typing conformance results

No changes detected ✅

Current numbers
The percentage of diagnostics emitted that were expected errors held steady at 87.07%. The percentage of expected errors that received a diagnostic held steady at 77.62%.

@astral-sh-bot

astral-sh-bot Bot commented Mar 6, 2026

Copy link
Copy Markdown

mypy_primer results

No ecosystem changes detected ✅

@astral-sh-bot

astral-sh-bot Bot commented Mar 6, 2026

Copy link
Copy Markdown

Memory usage report

Memory usage unchanged ✅

@charliermarsh
charliermarsh marked this pull request as ready for review March 6, 2026 01:11

@carljm carljm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks! Would be great to just clear out all these todo types with tighter validation instead (in separate PRs). It might reveal missing cases we should handle. If those are bigger features, they can remain more narrowly focused todo types.

}
}
Type::SpecialForm(SpecialFormType::Callable) => {
invalid_type_argument(self, slice)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

By not calling self.infer_type_expression(parameters) here (as the catch-all below does) we regress in missing out on some actionable nested diagnostics, e.g. in a case like type[Callable[..., Missing]] or a malformed Callable type expression inside type[].

@KotlinIsland

Copy link
Copy Markdown
Contributor

Any other special forms like Callable are not allowed as an argument to type.

Callable isn't a special form though, it's a normal class. i think this is a spec issue

@carljm

carljm commented Mar 6, 2026

Copy link
Copy Markdown
Contributor

@KotlinIsland Every type checker treats it as a special form, and typeshed defines it that way. Let's not debate that here. If you want to propose a spec change, go ahead, and we can discuss in the Discuss thread for that proposed change.

@charliermarsh
charliermarsh force-pushed the charlie/type-callable branch from 1d6de92 to c1ce778 Compare March 6, 2026 02:12
@charliermarsh
charliermarsh enabled auto-merge (squash) March 6, 2026 02:12
@charliermarsh
charliermarsh merged commit 07286ef into main Mar 6, 2026
50 checks passed
@charliermarsh
charliermarsh deleted the charlie/type-callable branch March 6, 2026 02:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

no error when assigning a non-callable type to type[Callable]

3 participants