> For the complete documentation index, see [llms.txt](https://igor-19.gitbook.io/qa/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://igor-19.gitbook.io/qa/avtomatizaciya-testirovaniya/python/oop-v-python-vo-vsekh-podrobnostyakh/anotaciya-tipov.md).

# Анотация типов

Аннотации типов – это способ объявить ожидаемые типы аргументов и возвращаемого значения функции, переменных и атрибутов.

Допустимые значения анотации типов

* конкретный класс, например *str* или *FrenchDeck*;
* параметризованный тип коллекции, например `list[int], tuple[str, float]` и т. д.;
* `typing.Optional`, например `Optional[str]`, для объявления поля, которое может принимать значения типа `str` или `None`.
* Переменную можно также инициализировать значением. (`var_name: some_type = a_value`)

> \[!info] Важно\
> на этапе импорта, когда модель загружается, Python читает их и строит словарь **annotations**, который typing.NamedTuple и @dataclass затем используют для дополнения класса.

```python
class DemoPlainClass:
	a: int # заносится в анотацию
	b: float = 1.1 # заносится в анотацию и проставляется значение атрибуту класса
	c = 'spam' # обычный атрибут класса, а не анотация
1234
```

* Для поля *a* заводится запись в `__annotations__`, но больше оно никак не используется: атрибут с именем *a* в классе не создается.
* Поле *b* сохраняется в аннотациях и, кроме того, становится атрибутом класса со значением `1.1`.
* *c* – это самый обычный атрибут класса, а не аннотация


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://igor-19.gitbook.io/qa/avtomatizaciya-testirovaniya/python/oop-v-python-vo-vsekh-podrobnostyakh/anotaciya-tipov.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
