Skip to content

Conversation

@sharkdp
Copy link
Contributor

@sharkdp sharkdp commented Nov 28, 2025

Summary

Allow Annotated[MyClass, …] instances to be instantiated.

Test Plan

New Markdown tests.

@sharkdp sharkdp added ty Multi-file analysis & type inference ecosystem-analyzer labels Nov 28, 2025
@astral-sh-bot
Copy link

astral-sh-bot bot commented Nov 28, 2025

Diagnostic diff on typing conformance tests

Changes were detected when running ty on typing conformance tests
--- old-output.txt	2025-11-28 08:43:48.579149249 +0000
+++ new-output.txt	2025-11-28 08:43:51.915166455 +0000
@@ -877,8 +877,6 @@
 qualifiers_annotated.py:79:7: error[invalid-argument-type] Argument to function `func4` is incorrect: Expected `type[Unknown]`, found `<typing.Annotated special form>`
 qualifiers_annotated.py:80:7: error[invalid-argument-type] Argument to function `func4` is incorrect: Expected `type[Unknown]`, found `<typing.Annotated special form>`
 qualifiers_annotated.py:86:1: error[call-non-callable] Object of type `typing.Annotated` is not callable
-qualifiers_annotated.py:87:1: error[call-non-callable] Object of type `GenericAlias` is not callable
-qualifiers_annotated.py:88:1: error[call-non-callable] Object of type `GenericAlias` is not callable
 qualifiers_final_annotation.py:18:7: error[invalid-type-form] Type qualifier `typing.Final` expected exactly 1 argument, got 2
 qualifiers_final_annotation.py:54:9: error[invalid-assignment] Cannot assign to final attribute `ID5` in `__init__` because it already has a value at class level
 qualifiers_final_annotation.py:65:9: error[invalid-assignment] Cannot assign to final attribute `ID7` on type `Self@method1`
@@ -1029,4 +1027,4 @@
 typeddicts_usage.py:28:17: error[missing-typed-dict-key] Missing required key 'name' in TypedDict `Movie` constructor
 typeddicts_usage.py:28:18: error[invalid-key] Unknown key "title" for TypedDict `Movie`: Unknown key "title"
 typeddicts_usage.py:40:24: error[invalid-type-form] The special form `typing.TypedDict` is not allowed in type expressions
-Found 1031 diagnostics
+Found 1029 diagnostics

@astral-sh-bot
Copy link

astral-sh-bot bot commented Nov 28, 2025

mypy_primer results

Changes were detected when running on open source projects
scikit-build-core (https://github.com/scikit-build/scikit-build-core)
- src/scikit_build_core/_logging.py:153:13: warning[unsupported-base] Unsupported class base with type `<class 'Mapping[str, Style]'> | <class 'Mapping[str, Divergent]'>`
- Found 43 diagnostics
+ Found 42 diagnostics

rotki (https://github.com/rotki/rotki)
+ rotkehlchen/accounting/structures/processed_event.py:85:75: warning[unused-ignore-comment] Unused blanket `type: ignore` directive
+ rotkehlchen/api/rest.py:1039:73: warning[unused-ignore-comment] Unused blanket `type: ignore` directive
- Found 2038 diagnostics
+ Found 2040 diagnostics

pydantic (https://github.com/pydantic/pydantic)
- pydantic/functional_serializers.py:457:36: error[call-non-callable] Object of type `GenericAlias` is not callable
- pydantic/functional_validators.py:824:36: error[call-non-callable] Object of type `GenericAlias` is not callable
- Found 6711 diagnostics
+ Found 6709 diagnostics

No memory usage changes detected ✅

@astral-sh-bot
Copy link

astral-sh-bot bot commented Nov 28, 2025

ecosystem-analyzer results

Lint rule Added Removed Changed
call-non-callable 0 2 0
Total 0 2 0

Full report with detailed diff (timing results)

@sharkdp sharkdp marked this pull request as ready for review November 28, 2025 08:54
@AlexWaygood
Copy link
Member

AlexWaygood commented Nov 28, 2025

Oh, the typing conformance suite results seem to suggest that we shouldn't do this: apparently the two lines where diagnostics are going away are places we're supposed to emit diagnostics. But it does make sense to me to just emulate what happens at runtime; I don't know why that rule exists in the spec (https://typing.python.org/en/latest/spec/qualifiers.html#annotated)

@sharkdp
Copy link
Contributor Author

sharkdp commented Nov 28, 2025

I don't know why that rule exists in the spec (typing.python.org/en/latest/spec/qualifiers.html#annotated)

Oh. I only looked at the typing.Annotated documentation and forgot to check the typing spec. This one: "An attempt to call Annotated (whether parameterized or not) should be treated as a type error by type checkers"? That's strange, yes. Moving this to draft for now.

@sharkdp sharkdp marked this pull request as draft November 28, 2025 09:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ecosystem-analyzer ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants