Skip to content

fix(decorator): unwrap type-alias Raises markers in Annotated metadata - #2

Merged
feodor-ra merged 1 commit into
mainfrom
fix/aliased-raises-marker-in-metadata
Jul 24, 2026
Merged

fix(decorator): unwrap type-alias Raises markers in Annotated metadata#2
feodor-ra merged 1 commit into
mainfrom
fix/aliased-raises-marker-in-metadata

Conversation

@feodor-ra

Copy link
Copy Markdown
Owner

Проблема

_find_raises находил Raises-маркеры только когда они стоят напрямую в слоте метаданных Annotated. Маркер, переиспользуемый через PEP 695 type-алиас (type Common = Raises[...]), лежит там как TypeAliasType, поэтому isinstance(meta, Raises) не срабатывал и маркер терялся молча:

type CommonRaises = Raises[FooError, BarError]
def foo() -> Annotated[str, CommonRaises, Raises[ZooError]]: ...
# раньше: находил только Raises[ZooError]

Алиас, оборачивающий всю аннотацию (type X = Annotated[Item, Raises[...]]), работал и раньше.

Изменение

  • Введён общий хелпер _unwrap_type_alias, применяемый к каждому элементу метаданных Annotated перед проверками (и переиспользованный в начале _find_raises и в _annotated_base). Теперь запись «алиас-маркер в метаданных» работает наравне с распаковкой кортежа.
  • Тесты: два кейса через реальный app.openapi() (алиас-маркер среди других + как единственный элемент). Покрытие остаётся 100%.
  • Доки: раздел гайда декоратора расширен до «формы записи, переиспользование и композиция» + описан новый вариант (EN + RU).
  • Заведена двуязычная страница CHANGELOG, вписана в навигацию mkdocs.
  • Bump версии → 1.0.1 (+ uv.lock).

Проверка

  • just test — 132 passed, branch coverage 100%.
  • just lint — ruff format/check + ty чисто.
  • just docs-build — строгая сборка без ошибок.

`_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.
@feodor-ra
feodor-ra merged commit 8ebce91 into main Jul 24, 2026
5 checks passed
@feodor-ra
feodor-ra deleted the fix/aliased-raises-marker-in-metadata branch July 24, 2026 21:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant