fix(decorator): unwrap type-alias Raises markers in Annotated metadata - #2
Merged
Merged
Conversation
`_find_raises` only matched `Raises` markers that appear directly in an `Annotated` metadata slot. A marker shared through a PEP 695 `type` alias (`type Common = Raises[...]`) sits there as a `TypeAliasType`, so `isinstance(meta, Raises)` failed and the marker was dropped silently. Add a shared `_unwrap_type_alias` helper and apply it to each metadata element before the checks (and reuse it at the annotation top and in `_annotated_base`). Aliasing the whole annotation already worked; this makes the aliased-marker-in-metadata spelling work on par with tuple unpacking. Also: docs (decorator guide gains a spellings/sharing/composition section and the new spelling; bilingual CHANGELOG page wired into mkdocs nav), bump to 1.0.1.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Проблема
_find_raisesнаходилRaises-маркеры только когда они стоят напрямую в слоте метаданныхAnnotated. Маркер, переиспользуемый через PEP 695type-алиас (type Common = Raises[...]), лежит там какTypeAliasType, поэтомуisinstance(meta, Raises)не срабатывал и маркер терялся молча:Алиас, оборачивающий всю аннотацию (
type X = Annotated[Item, Raises[...]]), работал и раньше.Изменение
_unwrap_type_alias, применяемый к каждому элементу метаданныхAnnotatedперед проверками (и переиспользованный в начале_find_raisesи в_annotated_base). Теперь запись «алиас-маркер в метаданных» работает наравне с распаковкой кортежа.app.openapi()(алиас-маркер среди других + как единственный элемент). Покрытие остаётся 100%.uv.lock).Проверка
just test— 132 passed, branch coverage 100%.just lint— ruff format/check + ty чисто.just docs-build— строгая сборка без ошибок.