{"id":466018,"date":"2025-07-04T09:00:18","date_gmt":"2025-07-04T09:00:18","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=466018"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=466018","title":{"rendered":"<span>\u0422\u0438\u043f\u0438\u0437\u0430\u0446\u0438\u044f \u0432 Python: \u043a\u0430\u043a \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 \u0441\u043f\u0430\u0441\u0430\u044e\u0442 \u0432\u0430\u0448 \u043a\u043e\u0434 \u0438 \u0443\u0441\u043a\u043e\u0440\u044f\u044e\u0442 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0443<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440!<\/p>\n<p>Python &#8212; \u044f\u0437\u044b\u043a \u0441 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0442\u0438\u043f\u0438\u0437\u0430\u0446\u0438\u0435\u0439. \u0425\u043e\u0440\u043e\u0448\u043e \u044d\u0442\u043e \u0438\u043b\u0438 \u043f\u043b\u043e\u0445\u043e? \u0421 \u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, \u044d\u0442\u043e \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438: \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u043e\u0431\u044a\u044f\u0432\u043b\u044f\u0442\u044c \u0438 \u0437\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u0442\u044c \u0442\u0438\u043f\u044b \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445. \u0421 \u0434\u0440\u0443\u0433\u043e\u0439, \u044d\u0442\u043e \u043e\u0448\u0438\u0431\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u0441\u043f\u043b\u044b\u0432\u0430\u044e\u0442 \u043f\u0440\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0435 \u0438\u043b\u0438&#8230; \u0447\u0435\u0440\u0435\u0437 \u043c\u0435\u0441\u044f\u0446 \u043f\u0440\u043e\u0434\u0430\u043a\u0448\u0435\u043d\u0430.<br \/>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u043f\u043e\u043a\u0430\u0436\u0443, \u043f\u043e\u0447\u0435\u043c\u0443 <strong><em>type hinting<\/em><\/strong> &#8212; \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u044d\u043a\u043e\u043d\u043e\u043c\u0438\u0442 \u0447\u0430\u0441\u044b \u043e\u0442\u043b\u0430\u0434\u043a\u0438 \u0438 \u0441\u0434\u0435\u043b\u0430\u0435\u0442 \u043a\u043e\u0434 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u0435\u0435. <\/p>\n<h2>\u041d\u0430\u0447\u0438\u043d\u0430\u0435\u043c \u043d\u0430\u0447\u0438\u043d\u0430\u0442\u044c<\/h2>\n<p>\u0410\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 \u0442\u0438\u043f\u043e\u0432 \u0432\u043f\u0435\u0440\u0432\u044b\u0435 \u0431\u044b\u043b\u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u044b \u0432 Python 3.5, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u044f\u0432\u0438\u043b\u0441\u044f \u0432 2015 \u0433\u043e\u0434\u0443. \u041d\u043e \u0434\u043e \u0441\u0438\u0445 \u043f\u043e\u0440 \u043c\u043d\u043e\u0433\u0438\u0435 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u044e\u0442 \u043f\u0438\u0441\u0430\u0442\u044c \u043a\u043e\u0434 \u0432 \u0441\u0442\u0430\u0440\u043e\u043c \u0441\u0442\u0438\u043b\u0435. \u0412\u043e\u0437\u044c\u043c\u0435\u043c \u0442\u0438\u043f\u0438\u0447\u043d\u044b\u0439 \u043a\u043e\u0434  \u0442\u0438\u043f\u0438\u0447\u043d\u043e\u0433\u043e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430:<\/p>\n<pre><code class=\"python\">def process_user_data(user_data):     return user_data['name'].upper()<\/code><\/pre>\n<p>\u041d\u0430 \u043f\u0435\u0440\u0432\u044b\u0439 \u0432\u0437\u0433\u043b\u044f\u0434 &#8212; \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0441 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u044b\u043c \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c. \u041d\u043e \u0432 \u043d\u0435\u0439 \u043a\u0440\u043e\u044e\u0442\u0441\u044f \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u043e\u0431\u043b\u0435\u043c:<\/p>\n<ol>\n<li>\n<p><strong>\u041d\u0435\u043f\u0440\u043e\u0437\u0440\u0430\u0447\u043d\u043e\u0441\u0442\u044c \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442\u0430<\/strong>\u00a0&#8212; \u0431\u0435\u0437 \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043d\u044f\u0442\u044c:<\/p>\n<ul>\n<li>\n<p>\u041a\u0430\u043a\u0438\u0435 \u0442\u0438\u043f\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u043e\u0436\u0438\u0434\u0430\u044e\u0442\u0441\u044f?<\/p>\n<\/li>\n<li>\n<p>\u041a\u0430\u043a\u043e\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c\u00a0<code>user_data<\/code>?<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u0425\u0440\u0443\u043f\u043a\u043e\u0441\u0442\u044c &#8212; \u043d\u0435 \u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u0447\u0442\u043e \u0432\u0435\u0440\u043d\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u0448\u0438\u0431\u043a\u0438<\/p>\n<\/li>\n<\/ol>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0443\u043b\u0443\u0447\u0448\u0438\u043c \u043a\u043e\u0434 \u0438 \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c \u043a\u0430\u0436\u0434\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442:<\/p>\n<pre><code class=\"python\">from typing import TypedDict  class UserData(TypedDict):     id: int     name: str  def get_user_name(user_data: UserData) -&gt; str:     return user_data[\"name\"].upper()<\/code><\/pre>\n<p><strong>\u041a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438:<\/strong><\/p>\n<ol>\n<li>\n<p>\u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b:\u00a0<code>arg: type<\/code>\u00a0(\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440,\u00a0<code>user_data: UserData<\/code>)<\/p>\n<\/li>\n<li>\n<p>\u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435:\u00a0<code>-&gt; return_type<\/code>\u00a0(\u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435\u00a0<code>-&gt; str<\/code>)<\/p>\n<\/li>\n<\/ol>\n<h4>\u0411\u0430\u0437\u043e\u0432\u044b\u0435 \u0442\u0438\u043f\u044b (\u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u044b)<\/h4>\n<p>\u0421\u0430\u043c\u044b\u0435 \u043f\u0440\u043e\u0441\u0442\u044b\u0435 \u0438 \u0447\u0430\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0435 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438:<\/p>\n<pre><code class=\"python\">from numbers import Real   def add(a: int, b: int) -&gt; int:   return a + b   def add(a: Real, b: Real) -&gt; Real:   return a + b   def greet(name: str) -&gt; str:   return f\"Hello {name}\"   def is_active(status: bool) -&gt; bool:   return status<\/code><\/pre>\n<p>\u0421 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044f\u043c\u0438 \u0442\u0438\u043f\u043e\u0432 \u0434\u0430\u0436\u0435 \u0441\u0430\u043c\u044b\u0435 \u043f\u0440\u043e\u0441\u0442\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0441\u0442\u0430\u043d\u043e\u0432\u044f\u0442\u0441\u044f \u043f\u043e\u043d\u044f\u0442\u043d\u0435\u0435 \u0438 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u0435\u0435, \u0432\u0435\u0434\u044c \u0432\u0430\u0448\u0430 IDE \u043f\u043e\u0434\u0441\u043a\u0430\u0436\u0435\u0442, \u0435\u0441\u043b\u0438 \u0432\u044b \u043f\u043e\u043f\u044b\u0442\u0430\u0435\u0442\u0435\u0441\u044c \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 \u0442\u0438\u043f. <\/p>\n<p><strong>\u0412\u0430\u0436\u043d\u043e \u043f\u043e\u043c\u043d\u0438\u0442\u044c, \u0447\u0442\u043e, \u0434\u0430\u0436\u0435 \u043f\u0440\u0438 \u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u0445, \u0432\u0430\u0448 \u043a\u043e\u0434 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u0441\u044f.<\/strong> \u0410\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 \u0441\u043b\u0443\u0436\u0430\u0442 \u043b\u0438\u0448\u044c \u043f\u043e\u0434\u0441\u043a\u0430\u0437\u043a\u043e\u0439 \u0434\u043b\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430. <\/p>\n<p><strong>\u0415\u0441\u043b\u0438 \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u0431\u043e\u043b\u044c\u0448\u0435 \u0443\u0437\u043d\u0430\u0442\u044c \u043e\u0431 AI \u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u043d\u0430 Python, \u043f\u043e\u0434\u043f\u0438\u0441\u044b\u0432\u0430\u0439\u0442\u0435\u0441\u044c \u043d\u0430 \u043c\u043e\u0439 \u0442\u0435\u043b\u0435\u0433\u0440\u0430\u043c\u043c \u043a\u0430\u043d\u0430\u043b:<\/strong><\/p>\n<p><a href=\"https:\/\/t.me\/Viacheslav_Talks\" rel=\"noopener noreferrer nofollow\">https:\/\/t.me\/Viacheslav_Talks<\/a>  <\/p>\n<p><strong>Union, Optional, Literal<\/strong><\/p>\n<p><strong>Union <\/strong>\u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <em>int\/float<\/em><\/p>\n<pre><code class=\"python\">from typing import Union   def add(a: Union[int, float], b: Union[int, float]) -&gt; Union[int, float]:   return a + b<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u00a0<code>add<\/code>\u00a0\u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u0442\u0438\u043f\u0430\u00a0<code>int<\/code>\u00a0\u0438\u043b\u0438\u00a0<code>float<\/code>\u00a0\u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0442\u043e\u0433\u043e \u0436\u0435 \u0442\u0438\u043f\u0430.  <\/p>\n<pre><code class=\"python\">def get_element(d: dict[str, str], key: str) -&gt; Union[str, None]:   return d.get(key, None)<\/code><\/pre>\n<p><strong>Optional  <\/strong>&#8212; \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442, \u0447\u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043b\u0438\u0431\u043e \u0442\u0438\u043f\u0430 <em>T<\/em>, \u043b\u0438\u0431\u043e <em>None<\/em>. \u042d\u0442\u043e \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u043d\u043e <em>Union[T, None]<\/em><\/p>\n<pre><code class=\"python\">user_name: Optional[str] = None<\/code><\/pre>\n<p>\u041a\u043b\u0430\u0441\u0441\u044b \u0441 \u043e\u043f\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u043f\u043e\u043b\u044f\u043c\u0438:<\/p>\n<pre><code class=\"python\">class User:     def __init__(self, name: str, phone: Optional[str] = None):         self.name = name         self.phone = phone  # \u0422\u0435\u043b\u0435\u0444\u043e\u043d \u043c\u043e\u0436\u0435\u0442 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c  user1 = User(\"\u0412\u0430\u043d\u044f\", \"+999999999\") user2 = User(\"\u041f\u0435\u0442\u044f\")<\/code><\/pre>\n<p><code>Literal<\/code>\u00a0\u0436\u0451\u0441\u0442\u043a\u043e \u0444\u0438\u043a\u0441\u0438\u0440\u0443\u0435\u0442 \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c\u044b\u0435 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b. \u0418\u0434\u0435\u0430\u043b\u0435\u043d \u0434\u043b\u044f:<\/p>\n<ul>\n<li>\n<p>\u0441\u0442\u0430\u0442\u0443\u0441\u043e\u0432 (<code>\"active\"<\/code>,\u00a0<code>\"pending\"<\/code>,\u00a0<code>\"completed\"<\/code>)<\/p>\n<\/li>\n<li>\n<p>HTTP-\u043c\u0435\u0442\u043e\u0434\u043e\u0432 (<code>\"GET\"<\/code>,\u00a0<code>\"POST\"<\/code>,\u00a0<code>\"PUT\"<\/code>)<\/p>\n<\/li>\n<li>\n<p>\u043b\u044e\u0431\u044b\u0445 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"python\">HttpMethod = Literal[\"GET\", \"POST\", \"PUT\", \"DELETE\"]  def send_request(method: HttpMethod, url: str) -&gt; None:     print(f\"{method} \u0437\u0430\u043f\u0440\u043e\u0441 \u043a {url}\")  send_request(\"POST\", \"\/api\")  # OK send_request(\"PATCH\", \"\/\")  # \u041e\u0448\u0438\u0431\u043a\u0430 \u0442\u0438\u043f\u0430<\/code><\/pre>\n<pre><code class=\"python\">from typing import Literal  def set_status(status: Literal[\"active\", \"inactive\", \"pending\"]) -&gt; None:     print(f\"\u0421\u0442\u0430\u0442\u0443\u0441 \u0438\u0437\u043c\u0435\u043d\u0451\u043d \u043d\u0430: {status}\")  set_status(\"active\")  # OK set_status(\"deleted\")  # \u041e\u0448\u0438\u0431\u043a\u0430 \u0432 mypy: \u043d\u0435\u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435<\/code><\/pre>\n<h4>\u0410\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 \u0434\u043b\u044f \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0439: \u0441\u043f\u0438\u0441\u043a\u0438, \u0441\u043b\u043e\u0432\u0430\u0440\u0438, \u043a\u043e\u0440\u0442\u0435\u0436\u0438<\/h4>\n<p>Python \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0442\u0438\u043f\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u044b, \u043d\u043e \u0438 \u0441\u043b\u043e\u0436\u043d\u044b\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<pre><code class=\"python\">def find_item(d: dict[str, int], key: str) -&gt; int | None:   return d.get(key)<\/code><\/pre>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f \u043e\u0436\u0438\u0434\u0430\u0435\u0442 \u043d\u0430 \u0432\u0445\u043e\u0434 \u0441\u043b\u043e\u0432\u0430\u0440\u044c, \u0433\u0434\u0435 \u043a\u043b\u044e\u0447\u043e\u043c \u0431\u0443\u0434\u0435\u0442 \u0441\u0442\u0440\u043e\u043a\u0430, \u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c &#8212; \u0447\u0438\u0441\u043b\u043e\u043c. \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043b\u0438\u0431\u043e <em>\u0447\u0438\u0441\u043b\u043e<\/em>, \u043b\u0438\u0431\u043e <em>None<\/em>. <\/p>\n<h4>TypedDict<\/h4>\n<p><code>TypedDict<\/code>\u00a0\u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u044f\u0432\u043d\u043e \u043e\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u043b\u043e\u0432\u0430\u0440\u044c:<\/p>\n<ul>\n<li>\n<p>\u041a\u0430\u043a\u0438\u0435 \u043a\u043b\u044e\u0447\u0438 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b<\/p>\n<\/li>\n<li>\n<p>\u041a\u0430\u043a\u0438\u0435 \u0442\u0438\u043f\u044b \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0443 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043a\u043b\u044e\u0447\u0430<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"python\">from typing import TypedDict  class ServerConfig(TypedDict):   host: str   port: int   ssl: bool   def start_server(config: ServerConfig):   print(f\"Starting server with config: {config}\")  config: ServerConfig  = {\"host\": \"localhost\", \"port\": 8080, \"ssl\": False} start_server(config)   <\/code><\/pre>\n<p><em>TypedDict<\/em> \u0434\u043b\u044f \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445. \u0410\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 \u0442\u0438\u043f\u043e\u0432 \u0438 \u0442\u0438\u043f\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0445\u043e\u0440\u043e\u0448\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0442 \u0434\u043b\u044f \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445<\/p>\n<pre><code class=\"python\">class Book(TypedDict):   title: str   year: int   def validate_book(date: dict) -&gt; Book:   required_keys = {\"title\", \"year\"}    if not all(key in data for key in required_keys):     return None   return Book(**data)  raw_data  = {\"title\": \"Python\", \"year\": 2005} book: Book | None  = validate_book(raw_data)  if book:   print(book[\"title\"])<\/code><\/pre>\n<p><strong>NamedTuple<\/strong><\/p>\n<p>\u041a\u043e\u0440\u0442\u0435\u0436  \u0443\u0434\u043e\u0431\u043d\u044b \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u043d\u0435\u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, DTO. \u041d\u043e \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0435 \u043a \u043f\u043e\u043b\u044f\u043c \u043f\u043e \u0438\u043d\u0434\u0435\u043a\u0441\u0430\u043c (<code>[0]<\/code>,\u00a0<code>[1]<\/code>) \u2014 \u043d\u0435\u043d\u0430\u0434\u0451\u0436\u043d\u043e \u0438 \u0443\u0441\u043b\u043e\u0436\u043d\u044f\u0435\u0442 \u0447\u0442\u0435\u043d\u0438\u0435 \u043a\u043e\u0434\u0430.\u00a0<code><strong>NamedTuple<\/strong><\/code><strong>\u00a0<\/strong>\u0440\u0435\u0448\u0430\u0435\u0442 \u044d\u0442\u0443 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443, <\/p>\n<pre><code class=\"python\">from typing import NamedTuple   class Product(NamedTuple):   name: str   price: int   quantity: int   def total_value(product: Product) -&gt; int:   return product.price * product.quantity<\/code><\/pre>\n<h2>Callable, Generator<\/h2>\n<p>\u0414\u043b\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0442\u0430\u043a \u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438. \u042d\u0442\u043e \u043f\u043e\u043b\u0435\u0437\u043d\u043e \u0434\u043b\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0432\u044b\u0441\u0448\u0438\u0445 \u043f\u043e\u0440\u044f\u0434\u043e\u043a, \u043a\u043e\u043b\u0431\u044d\u043a\u043e\u0432, \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432. \u041d\u0430\u043f\u0438\u0448\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u0434\u0440\u0443\u0433\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0441 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u043c\u0438 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430\u043c\u0438. <\/p>\n<pre><code class=\"python\">def send_messages(on_success: Callable[[], None]),                    on_failure: Callable[[Exception], None],                   ) -&gt; None:       if random.random() &lt; 0.5:         return on_success()       return on_failure(Exception('something went wrong'))       def on_success() -&gt; None:   print(\"success\")   def on_failure(exception: Exception) -&gt; None:   print(exception)   send_messages(on_success, on_failure)<\/code><\/pre>\n<p>\u0410\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044f \u0434\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432 \u0438\u043c\u0435\u0435\u0442 \u0432\u0438\u0434:<\/p>\n<p><code><strong><em>Generator[YieldType, SendType, ReturnType]<\/em><\/strong><\/code><\/p>\n<p><em>YieldType <\/em>&#8212; \u0442\u0438\u043f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440 \u0432\u044b\u0434\u0430\u0435\u0442 \u0447\u0435\u0440\u0435\u0437 yield <\/p>\n<p><em>SendType  <\/em>&#8212; \u0442\u0438\u043f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442\u0441\u044f \u0432 \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440 \u0447\u0435\u0440\u0435\u0437 send<\/p>\n<p><em>ReturnType <\/em>&#8212; \u0442\u0438\u043f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0433\u043e \u043f\u0440\u0438 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0438 \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u0430<\/p>\n<pre><code class=\"python\">from typing import Generator    def generator(words: list[str]) -&gt; Generator[str, None, None]:   for word in words:     yield word   words  = [\"\u041c\u043e\u0441\u043a\u0432\u0430\", \"\u041f\u0438\u0442\u0435\u0440\", \"\u041a\u0430\u0437\u0430\u043d\u044c\"]  for word in word_generator(words):     print(word)   <\/code><\/pre>\n<h2>Generics<\/h2>\n<p>\u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043f\u0435\u0440\u0432\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0441\u043f\u0438\u0441\u043a\u0430\u00a0<strong>\u043b\u044e\u0431\u043e\u0433\u043e \u0442\u0438\u043f\u0430<\/strong>. \u0411\u0435\u0437 <em>Generics <\/em>\u0432\u0430\u043c \u0431\u044b \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044e <em>Any<\/em>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u044b\u043b\u0430 \u0431\u044b \u0431\u0435\u0441\u043f\u043e\u043b\u0435\u0437\u043d\u0430. <\/p>\n<pre><code class=\"python\">from typing import TypeVar   T  = TypeVar(\"T\")   def get_first_element(lst: list[T]) -&gt; T | None:   return lst[0] if lst else None<\/code><\/pre>\n<p>\u041d\u0430\u043f\u0438\u0448\u0435\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0441\u0442\u044d\u043a\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043e\u0434\u043d\u043e\u0433\u043e \u0442\u0438\u043f\u0430  \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c <em>Generics<\/em>:<\/p>\n<pre><code class=\"python\">class Stack(Generic[T]):   def __init__(self):     self.stack: list[T] = []     def push(self, element: T) -&gt; None:     self.stack.append(element)    def pop(self) -&gt; T:     return self.stack.pop()     int_stack  = Stack[int]()   int_stack.push(1)   int_stack.push(\"1\") #IDE \u043f\u043e\u043a\u0430\u0436\u0435\u0442 \u043e\u0448\u0438\u0431\u043a\u0443<\/code><\/pre>\n<h2>\u0421\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 (TypeAlies,  NewType, Protocol)<\/h2>\n<p><strong>TypeAlias <\/strong><\/p>\n<p>\u041f\u043e\u043b\u0435\u0437\u0435\u043d, \u043a\u043e\u0433\u0434\u0430 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043e\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u043b\u043e\u0436\u043d\u0443\u044e \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043e\u0439 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442 \u043c\u043d\u043e\u0433\u043e \u043c\u0435\u0441\u0442\u0430. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u043e\u0433\u0434\u0430 \u043d\u0443\u0436\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044e \u0434\u043b\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043a\u0430\u043a \u043e\u0434\u043d\u043e\u043c \u0438\u0437 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u0432\u044b\u0448\u0435 <\/p>\n<pre><code class=\"python\">from typing import TypeAlias, Callable    func: TypeAlias  = Callable[[float, float], float]  def apply_operation(a: float, b: float, op: func) -&gt; float:   return op(a, b)   add_op: func  = lambda x, y: x + y print(apply_operation(1.2, 2.5, add))<\/code><\/pre>\n<p>\u0411\u0435\u0437 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f <em>TypeAlias <\/em>\u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u043b\u0430 \u0431\u044b \u0433\u0440\u043e\u043c\u043e\u0437\u0434\u043a\u043e\u0439. <\/p>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <em>TypeAlias <\/em>\u0434\u043b\u044f \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u044b\u0445 \u0441\u0441\u044b\u043b\u043e\u043a, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u043b\u044f \u0430\u043d\u043d\u043e\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f <em>JSON <\/em>\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u043e\u0442\u043b\u0438\u0447\u0430\u044e\u0442\u0441\u044f \u043e\u0442 \u043f\u0438\u0442\u043e\u043d\u043e\u0432\u0441\u043a\u0438\u0445. <\/p>\n<pre><code class=\"python\">from typing import TypeAlias, Union  Json: TypeAlias = Union[     str, int, float, bool, None,     dict[str, 'Json'],  # \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u0430\u044f \u0441\u0441\u044b\u043b\u043a\u0430     list['Json'] ]   def parse_json(data: Json) -&gt; None:     print(data)   data: Json = {     \"name\": \"ViacheslavVoo\",     \"scores\": [95, 87, 91],     \"metadata\": {\"active\": True, \"tags\": None}, }  parse_json(data)<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u0441\u0442\u043e\u0438\u0442 \u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e <em>IDE <\/em>\u043c\u043e\u0436\u0435\u0442 \u043d\u0435 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0443 \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0445 \u0442\u0438\u043f\u043e\u0432. \u0414\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u0438\u043b\u0438 \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u044b\u0445 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0439 \u0441\u0442\u043e\u0438\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <strong>mypy<\/strong>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u043a\u0430\u0436\u0435\u0442 \u043e\u0448\u0438\u0431\u043a\u0443. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u0440\u0438 \u043f\u043e\u043f\u044b\u0442\u043a\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <em>tuple<\/em>: <\/p>\n<pre><code class=\"yaml\">error: Dict entry 0 has incompatible type \"str\": \"tuple[int, int, int]\"; expected \"str\": \"str | int | float | dict[str, Json] | list[Json] | None\"  [dict-item] Found 1 error in 1 file (checked 1 source file)<\/code><\/pre>\n<p><strong>NewType<\/strong><\/p>\n<p>\u042d\u0442\u043e\u0442 \u0432\u0438\u0434 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0439 \u0441\u0442\u043e\u0438\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043d\u043e\u0432\u043e\u0433\u043e \u0442\u0438\u043f\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0433\u043e. \u041e\u0441\u043d\u043e\u0432\u043d\u043e\u0435 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 \u0434\u0440\u0443\u0433\u0438\u0445 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0439  &#8212; newtype \u043f\u043e\u0437\u0438\u0446\u0438\u043e\u043d\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u043e\u0431\u043e\u0441\u043e\u0431\u043b\u0435\u043d\u043d\u044b\u0439 \u0432\u0438\u0434 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445. \u0422\u043e \u0435\u0441\u0442\u044c <strong><em>NewType(&#187;, int) != int<\/em><\/strong>, \u0432 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 <em>TypeAlias<\/em>. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u0441\u043c\u044b\u0441\u043b\u043e\u0432\u043e\u0433\u043e \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u044f. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code class=\"python\">from typing import NewType  UserId  = NewType(\"UserId\", int) OrderId  = NewType(\"OrderId\", int)   def get_user(UserId) -&gt; None:   ...   user_id  = UserId(1) order_id  = OrderId(1)  get_user(user_id) get_user(order_id) #mypy \u043f\u043e\u043a\u0430\u0436\u0435\u0442 \u043e\u0448\u0438\u0431\u043a\u0443, \u0442\u0430\u043a \u043a\u0430\u043a UserId \u0438 OrderId  - \u0440\u0430\u0437\u043d\u044b\u0435 \u0442\u0438\u043f\u044b get_user(1) #\u043e\u0448\u0438\u0431\u043a\u0430, \u0442\u0430\u043a \u043a\u0430\u043a \u043e\u0436\u0438\u0434\u0430\u0435\u0442\u0441\u044f UserId<\/code><\/pre>\n<p>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435: \u0434\u043e \u0432\u0435\u0440\u0441\u0438\u0438 Python 3.10 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u0435 <em>NewType <\/em>\u043d\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u043b\u043e \u043d\u0430\u043a\u043b\u0430\u0434\u043d\u044b\u0445 \u0440\u0430\u0441\u0445\u043e\u0434\u043e\u0432, \u043d\u043e \u0432 \u0432\u0435\u0440\u0441\u0438\u0438 3.10 <em>NewType <\/em>\u0441\u0442\u0430\u043b \u043a\u043b\u0430\u0441\u0441\u043e\u043c \u043e\u0431\u0435\u0440\u0442\u043a\u043e\u0439. \u042d\u0442\u043e \u043f\u0440\u0438\u0431\u0430\u0432\u0438\u043b\u043e \u0437\u0430\u0442\u0440\u0430\u0442 \u0432\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f<strong>. \u0412 Python 3.11 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0432\u0435\u0440\u043d\u0443\u043b\u0438 \u043d\u0430 \u0443\u0440\u043e\u0432\u0435\u043d\u044c Python 3.9<\/strong> <\/p>\n<p><strong>Protocol<\/strong><\/p>\n<p><em>Protocol <\/em>\u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u044b \u043d\u0435 \u0445\u043e\u0442\u0438\u0442\u0435 \u044f\u0432\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u0438\u043b\u0438 \u043d\u0435 \u0438\u043c\u0435\u0435\u0442\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0443\u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c\u0441\u044f. \u041f\u043e\u0434 <em>Protocol <\/em>\u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442\u044c \u043b\u044e\u0431\u043e\u0439 \u043a\u043b\u0430\u0441\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u043c\u0435\u0435\u0442 \u043c\u0435\u0442\u043e\u0434 draw. \u0422\u0430\u043a\u0430\u044f \u0448\u0442\u0443\u043a\u0430 \u043a\u0440\u0430\u0439\u043d\u0435 \u043f\u043e\u043b\u0435\u0437\u043d\u0430 \u0434\u043b\u044f \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f <\/p>\n<pre><code class=\"python\">from typing import Protocol   class Drawable(Protocol):     def draw(self) -&gt; None:         ...   class Circle:     def draw(self) -&gt; None:         print(\"draw circle\")      def some_func(self):         print(\"some_func\")   def render(obj: Drawable):     obj.draw()   render(Circle())<\/code><\/pre>\n<p>\u0422\u0438\u043f\u0438\u0437\u0430\u0446\u0438\u044f \u0432 Python \u2014 \u044d\u0442\u043e \u043d\u0435 \u0441\u0442\u0440\u043e\u0433\u0438\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f, \u0430\u00a0\u0441\u043f\u043e\u0441\u043e\u0431 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043a\u043e\u0434 \u043f\u043e\u043d\u044f\u0442\u043d\u0435\u0435, \u043d\u0430\u0434\u0451\u0436\u043d\u0435\u0435 \u0438 \u0443\u0434\u043e\u0431\u043d\u0435\u0435. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 <em>Type hinting<\/em> \u0432 \u0441\u0432\u043e\u0438\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445 \u0438 \u044d\u0442\u043e \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u0441\u044d\u043a\u043e\u043d\u043e\u043c\u0438\u0442\u044c \u0432\u0430\u043c \u0447\u0430\u0441\u044b \u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433\u0430 \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442 \u043d\u0435\u0440\u0432\u044b \u043d\u043e\u0432\u044b\u043c \u0441\u043e\u0442\u0440\u0443\u0434\u043d\u0438\u043a\u0430\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0442\u044c \u0432\u0430\u0448 \u043a\u043e\u0434<\/p>\n<p><strong>\u0421\u043f\u0430\u0441\u0438\u0431\u043e \u0437\u0430 \u043f\u0440\u043e\u0447\u0442\u0435\u043d\u0438\u0435! <\/strong><\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/924836\/\"> https:\/\/habr.com\/ru\/articles\/924836\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440!<\/p>\n<p>Python &#8212; \u044f\u0437\u044b\u043a \u0441 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0442\u0438\u043f\u0438\u0437\u0430\u0446\u0438\u0435\u0439. \u0425\u043e\u0440\u043e\u0448\u043e \u044d\u0442\u043e \u0438\u043b\u0438 \u043f\u043b\u043e\u0445\u043e? \u0421 \u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, \u044d\u0442\u043e \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438: \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u043e\u0431\u044a\u044f\u0432\u043b\u044f\u0442\u044c \u0438 \u0437\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u0442\u044c \u0442\u0438\u043f\u044b \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445. \u0421 \u0434\u0440\u0443\u0433\u043e\u0439, \u044d\u0442\u043e \u043e\u0448\u0438\u0431\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u0441\u043f\u043b\u044b\u0432\u0430\u044e\u0442 \u043f\u0440\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0435 \u0438\u043b\u0438&#8230; \u0447\u0435\u0440\u0435\u0437 \u043c\u0435\u0441\u044f\u0446 \u043f\u0440\u043e\u0434\u0430\u043a\u0448\u0435\u043d\u0430.<br \/>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u043f\u043e\u043a\u0430\u0436\u0443, \u043f\u043e\u0447\u0435\u043c\u0443 <strong><em>type hinting<\/em><\/strong> &#8212; \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u044d\u043a\u043e\u043d\u043e\u043c\u0438\u0442 \u0447\u0430\u0441\u044b \u043e\u0442\u043b\u0430\u0434\u043a\u0438 \u0438 \u0441\u0434\u0435\u043b\u0430\u0435\u0442 \u043a\u043e\u0434 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u0435\u0435. <\/p>\n<h2>\u041d\u0430\u0447\u0438\u043d\u0430\u0435\u043c \u043d\u0430\u0447\u0438\u043d\u0430\u0442\u044c<\/h2>\n<p>\u0410\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 \u0442\u0438\u043f\u043e\u0432 \u0432\u043f\u0435\u0440\u0432\u044b\u0435 \u0431\u044b\u043b\u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u044b \u0432 Python 3.5, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u044f\u0432\u0438\u043b\u0441\u044f \u0432 2015 \u0433\u043e\u0434\u0443. \u041d\u043e \u0434\u043e \u0441\u0438\u0445 \u043f\u043e\u0440 \u043c\u043d\u043e\u0433\u0438\u0435 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u044e\u0442 \u043f\u0438\u0441\u0430\u0442\u044c \u043a\u043e\u0434 \u0432 \u0441\u0442\u0430\u0440\u043e\u043c \u0441\u0442\u0438\u043b\u0435. \u0412\u043e\u0437\u044c\u043c\u0435\u043c \u0442\u0438\u043f\u0438\u0447\u043d\u044b\u0439 \u043a\u043e\u0434  \u0442\u0438\u043f\u0438\u0447\u043d\u043e\u0433\u043e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430:<\/p>\n<pre><code class=\"python\">def process_user_data(user_data):     return user_data['name'].upper()<\/code><\/pre>\n<p>\u041d\u0430 \u043f\u0435\u0440\u0432\u044b\u0439 \u0432\u0437\u0433\u043b\u044f\u0434 &#8212; \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0441 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u044b\u043c \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c. \u041d\u043e \u0432 \u043d\u0435\u0439 \u043a\u0440\u043e\u044e\u0442\u0441\u044f \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u043e\u0431\u043b\u0435\u043c:<\/p>\n<ol>\n<li>\n<p><strong>\u041d\u0435\u043f\u0440\u043e\u0437\u0440\u0430\u0447\u043d\u043e\u0441\u0442\u044c \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442\u0430<\/strong>\u00a0&#8212; \u0431\u0435\u0437 \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043d\u044f\u0442\u044c:<\/p>\n<ul>\n<li>\n<p>\u041a\u0430\u043a\u0438\u0435 \u0442\u0438\u043f\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u043e\u0436\u0438\u0434\u0430\u044e\u0442\u0441\u044f?<\/p>\n<\/li>\n<li>\n<p>\u041a\u0430\u043a\u043e\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c\u00a0<code>user_data<\/code>?<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u0425\u0440\u0443\u043f\u043a\u043e\u0441\u0442\u044c &#8212; \u043d\u0435 \u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u0447\u0442\u043e \u0432\u0435\u0440\u043d\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u0448\u0438\u0431\u043a\u0438<\/p>\n<\/li>\n<\/ol>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0443\u043b\u0443\u0447\u0448\u0438\u043c \u043a\u043e\u0434 \u0438 \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c \u043a\u0430\u0436\u0434\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442:<\/p>\n<pre><code class=\"python\">from typing import TypedDict  class UserData(TypedDict):     id: int     name: str  def get_user_name(user_data: UserData) -&gt; str:     return user_data[\"name\"].upper()<\/code><\/pre>\n<p><strong>\u041a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438:<\/strong><\/p>\n<ol>\n<li>\n<p>\u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b:\u00a0<code>arg: type<\/code>\u00a0(\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440,\u00a0<code>user_data: UserData<\/code>)<\/p>\n<\/li>\n<li>\n<p>\u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435:\u00a0<code>-&gt; return_type<\/code>\u00a0(\u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435\u00a0<code>-&gt; str<\/code>)<\/p>\n<\/li>\n<\/ol>\n<h4>\u0411\u0430\u0437\u043e\u0432\u044b\u0435 \u0442\u0438\u043f\u044b (\u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u044b)<\/h4>\n<p>\u0421\u0430\u043c\u044b\u0435 \u043f\u0440\u043e\u0441\u0442\u044b\u0435 \u0438 \u0447\u0430\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0435 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438:<\/p>\n<pre><code class=\"python\">from numbers import Real   def add(a: int, b: int) -&gt; int:   return a + b   def add(a: Real, b: Real) -&gt; Real:   return a + b   def greet(name: str) -&gt; str:   return f\"Hello {name}\"   def is_active(status: bool) -&gt; bool:   return status<\/code><\/pre>\n<p>\u0421 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044f\u043c\u0438 \u0442\u0438\u043f\u043e\u0432 \u0434\u0430\u0436\u0435 \u0441\u0430\u043c\u044b\u0435 \u043f\u0440\u043e\u0441\u0442\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0441\u0442\u0430\u043d\u043e\u0432\u044f\u0442\u0441\u044f \u043f\u043e\u043d\u044f\u0442\u043d\u0435\u0435 \u0438 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u0435\u0435, \u0432\u0435\u0434\u044c \u0432\u0430\u0448\u0430 IDE \u043f\u043e\u0434\u0441\u043a\u0430\u0436\u0435\u0442, \u0435\u0441\u043b\u0438 \u0432\u044b \u043f\u043e\u043f\u044b\u0442\u0430\u0435\u0442\u0435\u0441\u044c \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 \u0442\u0438\u043f. <\/p>\n<p><strong>\u0412\u0430\u0436\u043d\u043e \u043f\u043e\u043c\u043d\u0438\u0442\u044c, \u0447\u0442\u043e, \u0434\u0430\u0436\u0435 \u043f\u0440\u0438 \u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u0445, \u0432\u0430\u0448 \u043a\u043e\u0434 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u0441\u044f.<\/strong> \u0410\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 \u0441\u043b\u0443\u0436\u0430\u0442 \u043b\u0438\u0448\u044c \u043f\u043e\u0434\u0441\u043a\u0430\u0437\u043a\u043e\u0439 \u0434\u043b\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430. <\/p>\n<p><strong>\u0415\u0441\u043b\u0438 \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u0431\u043e\u043b\u044c\u0448\u0435 \u0443\u0437\u043d\u0430\u0442\u044c \u043e\u0431 AI \u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u043d\u0430 Python, \u043f\u043e\u0434\u043f\u0438\u0441\u044b\u0432\u0430\u0439\u0442\u0435\u0441\u044c \u043d\u0430 \u043c\u043e\u0439 \u0442\u0435\u043b\u0435\u0433\u0440\u0430\u043c\u043c \u043a\u0430\u043d\u0430\u043b:<\/strong><\/p>\n<p><a href=\"https:\/\/t.me\/Viacheslav_Talks\" rel=\"noopener noreferrer nofollow\">https:\/\/t.me\/Viacheslav_Talks<\/a>  <\/p>\n<p><strong>Union, Optional, Literal<\/strong><\/p>\n<p><strong>Union <\/strong>\u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <em>int\/float<\/em><\/p>\n<pre><code class=\"python\">from typing import Union   def add(a: Union[int, float], b: Union[int, float]) -&gt; Union[int, float]:   return a + b<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u00a0<code>add<\/code>\u00a0\u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u0442\u0438\u043f\u0430\u00a0<code>int<\/code>\u00a0\u0438\u043b\u0438\u00a0<code>float<\/code>\u00a0\u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0442\u043e\u0433\u043e \u0436\u0435 \u0442\u0438\u043f\u0430.  <\/p>\n<pre><code class=\"python\">def get_element(d: dict[str, str], key: str) -&gt; Union[str, None]:   return d.get(key, None)<\/code><\/pre>\n<p><strong>Optional  <\/strong>&#8212; \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442, \u0447\u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043b\u0438\u0431\u043e \u0442\u0438\u043f\u0430 <em>T<\/em>, \u043b\u0438\u0431\u043e <em>None<\/em>. \u042d\u0442\u043e \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u043d\u043e <em>Union[T, None]<\/em><\/p>\n<pre><code class=\"python\">user_name: Optional[str] = None<\/code><\/pre>\n<p>\u041a\u043b\u0430\u0441\u0441\u044b \u0441 \u043e\u043f\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u043f\u043e\u043b\u044f\u043c\u0438:<\/p>\n<pre><code class=\"python\">class User:     def __init__(self, name: str, phone: Optional[str] = None):         self.name = name         self.phone = phone  # \u0422\u0435\u043b\u0435\u0444\u043e\u043d \u043c\u043e\u0436\u0435\u0442 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c  user1 = User(\"\u0412\u0430\u043d\u044f\", \"+999999999\") user2 = User(\"\u041f\u0435\u0442\u044f\")<\/code><\/pre>\n<p><code>Literal<\/code>\u00a0\u0436\u0451\u0441\u0442\u043a\u043e \u0444\u0438\u043a\u0441\u0438\u0440\u0443\u0435\u0442 \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c\u044b\u0435 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b. \u0418\u0434\u0435\u0430\u043b\u0435\u043d \u0434\u043b\u044f:<\/p>\n<ul>\n<li>\n<p>\u0441\u0442\u0430\u0442\u0443\u0441\u043e\u0432 (<code>\"active\"<\/code>,\u00a0<code>\"pending\"<\/code>,\u00a0<code>\"completed\"<\/code>)<\/p>\n<\/li>\n<li>\n<p>HTTP-\u043c\u0435\u0442\u043e\u0434\u043e\u0432 (<code>\"GET\"<\/code>,\u00a0<code>\"POST\"<\/code>,\u00a0<code>\"PUT\"<\/code>)<\/p>\n<\/li>\n<li>\n<p>\u043b\u044e\u0431\u044b\u0445 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"python\">HttpMethod = Literal[\"GET\", \"POST\", \"PUT\", \"DELETE\"]  def send_request(method: HttpMethod, url: str) -&gt; None:     print(f\"{method} \u0437\u0430\u043f\u0440\u043e\u0441 \u043a {url}\")  send_request(\"POST\", \"\/api\")  # OK send_request(\"PATCH\", \"\/\")  # \u041e\u0448\u0438\u0431\u043a\u0430 \u0442\u0438\u043f\u0430<\/code><\/pre>\n<pre><code class=\"python\">from typing import Literal  def set_status(status: Literal[\"active\", \"inactive\", \"pending\"]) -&gt; None:     print(f\"\u0421\u0442\u0430\u0442\u0443\u0441 \u0438\u0437\u043c\u0435\u043d\u0451\u043d \u043d\u0430: {status}\")  set_status(\"active\")  # OK set_status(\"deleted\")  # \u041e\u0448\u0438\u0431\u043a\u0430 \u0432 mypy: \u043d\u0435\u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435<\/code><\/pre>\n<h4>\u0410\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 \u0434\u043b\u044f \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0439: \u0441\u043f\u0438\u0441\u043a\u0438, \u0441\u043b\u043e\u0432\u0430\u0440\u0438, \u043a\u043e\u0440\u0442\u0435\u0436\u0438<\/h4>\n<p>Python \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0442\u0438\u043f\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u044b, \u043d\u043e \u0438 \u0441\u043b\u043e\u0436\u043d\u044b\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<pre><code class=\"python\">def find_item(d: dict[str, int], key: str) -&gt; int | None:   return d.get(key)<\/code><\/pre>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f \u043e\u0436\u0438\u0434\u0430\u0435\u0442 \u043d\u0430 \u0432\u0445\u043e\u0434 \u0441\u043b\u043e\u0432\u0430\u0440\u044c, \u0433\u0434\u0435 \u043a\u043b\u044e\u0447\u043e\u043c \u0431\u0443\u0434\u0435\u0442 \u0441\u0442\u0440\u043e\u043a\u0430, \u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c &#8212; \u0447\u0438\u0441\u043b\u043e\u043c. \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043b\u0438\u0431\u043e <em>\u0447\u0438\u0441\u043b\u043e<\/em>, \u043b\u0438\u0431\u043e <em>None<\/em>. <\/p>\n<h4>TypedDict<\/h4>\n<p><code>TypedDict<\/code>\u00a0\u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u044f\u0432\u043d\u043e \u043e\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u043b\u043e\u0432\u0430\u0440\u044c:<\/p>\n<ul>\n<li>\n<p>\u041a\u0430\u043a\u0438\u0435 \u043a\u043b\u044e\u0447\u0438 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b<\/p>\n<\/li>\n<li>\n<p>\u041a\u0430\u043a\u0438\u0435 \u0442\u0438\u043f\u044b \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0443 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043a\u043b\u044e\u0447\u0430<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"python\">from typing import TypedDict  class ServerConfig(TypedDict):   host: str   port: int   ssl: bool   def start_server(config: ServerConfig):   print(f\"Starting server with config: {config}\")  config: ServerConfig  = {\"host\": \"localhost\", \"port\": 8080, \"ssl\": False} start_server(config)   <\/code><\/pre>\n<p><em>TypedDict<\/em> \u0434\u043b\u044f \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445. \u0410\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 \u0442\u0438\u043f\u043e\u0432 \u0438 \u0442\u0438\u043f\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0445\u043e\u0440\u043e\u0448\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0442 \u0434\u043b\u044f \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445<\/p>\n<pre><code class=\"python\">class Book(TypedDict):   title: str   year: int   def validate_book(date: dict) -&gt; Book:   required_keys = {\"title\", \"year\"}    if not all(key in data for key in required_keys):     return None   return Book(**data)  raw_data  = {\"title\": \"Python\", \"year\": 2005} book: Book | None  = validate_book(raw_data)  if book:   print(book[\"title\"])<\/code><\/pre>\n<p><strong>NamedTuple<\/strong><\/p>\n<p>\u041a\u043e\u0440\u0442\u0435\u0436  \u0443\u0434\u043e\u0431\u043d\u044b \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u043d\u0435\u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, DTO. \u041d\u043e \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0435 \u043a \u043f\u043e\u043b\u044f\u043c \u043f\u043e \u0438\u043d\u0434\u0435\u043a\u0441\u0430\u043c (<code>[0]<\/code>,\u00a0<code>[1]<\/code>) \u2014 \u043d\u0435\u043d\u0430\u0434\u0451\u0436\u043d\u043e \u0438 \u0443\u0441\u043b\u043e\u0436\u043d\u044f\u0435\u0442 \u0447\u0442\u0435\u043d\u0438\u0435 \u043a\u043e\u0434\u0430.\u00a0<code><strong>NamedTuple<\/strong><\/code><strong>\u00a0<\/strong>\u0440\u0435\u0448\u0430\u0435\u0442 \u044d\u0442\u0443 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443, <\/p>\n<pre><code class=\"python\">from typing import NamedTuple   class Product(NamedTuple):   name: str   price: int   quantity: int   def total_value(product: Product) -&gt; int:   return product.price * product.quantity<\/code><\/pre>\n<h2>Callable, Generator<\/h2>\n<p>\u0414\u043b\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0442\u0430\u043a \u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438. \u042d\u0442\u043e \u043f\u043e\u043b\u0435\u0437\u043d\u043e \u0434\u043b\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0432\u044b\u0441\u0448\u0438\u0445 \u043f\u043e\u0440\u044f\u0434\u043e\u043a, \u043a\u043e\u043b\u0431\u044d\u043a\u043e\u0432, \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432. \u041d\u0430\u043f\u0438\u0448\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u0434\u0440\u0443\u0433\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0441 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u043c\u0438 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430\u043c\u0438. <\/p>\n<pre><code class=\"python\">def send_messages(on_success: Callable[[], None]),                    on_failure: Callable[[Exception], None],                   ) -&gt; None:       if random.random() &lt; 0.5:         return on_success()       return on_failure(Exception('something went wrong'))       def on_success() -&gt; None:   print(\"success\")   def on_failure(exception: Exception) -&gt; None:   print(exception)   send_messages(on_success, on_failure)<\/code><\/pre>\n<p>\u0410\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044f \u0434\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432 \u0438\u043c\u0435\u0435\u0442 \u0432\u0438\u0434:<\/p>\n<p><code><strong><em>Generator[YieldType, SendType, ReturnType]<\/em><\/strong><\/code><\/p>\n<p><em>YieldType <\/em>&#8212; \u0442\u0438\u043f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440 \u0432\u044b\u0434\u0430\u0435\u0442 \u0447\u0435\u0440\u0435\u0437 yield <\/p>\n<p><em>SendType  <\/em>&#8212; \u0442\u0438\u043f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442\u0441\u044f \u0432 \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440 \u0447\u0435\u0440\u0435\u0437 send<\/p>\n<p><em>ReturnType <\/em>&#8212; \u0442\u0438\u043f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0433\u043e \u043f\u0440\u0438 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0438 \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u0430<\/p>\n<pre><code class=\"python\">from typing import Generator    def generator(words: list[str]) -&gt; Generator[str, None, None]:   for word in words:     yield word   words  = [\"\u041c\u043e\u0441\u043a\u0432\u0430\", \"\u041f\u0438\u0442\u0435\u0440\", \"\u041a\u0430\u0437\u0430\u043d\u044c\"]  for word in word_generator(words):     print(word)   <\/code><\/pre>\n<h2>Generics<\/h2>\n<p>\u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043f\u0435\u0440\u0432\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0441\u043f\u0438\u0441\u043a\u0430\u00a0<strong>\u043b\u044e\u0431\u043e\u0433\u043e \u0442\u0438\u043f\u0430<\/strong>. \u0411\u0435\u0437 <em>Generics <\/em>\u0432\u0430\u043c \u0431\u044b \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044e <em>Any<\/em>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u044b\u043b\u0430 \u0431\u044b \u0431\u0435\u0441\u043f\u043e\u043b\u0435\u0437\u043d\u0430. <\/p>\n<pre><code class=\"python\">from typing import TypeVar   T  = TypeVar(\"T\")   def get_first_element(lst: list[T]) -&gt; T | None:   return lst[0] if lst else None<\/code><\/pre>\n<p>\u041d\u0430\u043f\u0438\u0448\u0435\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0441\u0442\u044d\u043a\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043e\u0434\u043d\u043e\u0433\u043e \u0442\u0438\u043f\u0430  \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c <em>Generics<\/em>:<\/p>\n<pre><code class=\"python\">class Stack(Generic[T]):   def __init__(self):     self.stack: list[T] = []     def push(self, element: T) -&gt; None:     self.stack.append(element)    def pop(self) -&gt; T:     return self.stack.pop()     int_stack  = Stack[int]()   int_stack.push(1)   int_stack.push(\"1\") #IDE \u043f\u043e\u043a\u0430\u0436\u0435\u0442 \u043e\u0448\u0438\u0431\u043a\u0443<\/code><\/pre>\n<h2>\u0421\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 (TypeAlies,  NewType, Protocol)<\/h2>\n<p><strong>TypeAlias <\/strong><\/p>\n<p>\u041f\u043e\u043b\u0435\u0437\u0435\u043d, \u043a\u043e\u0433\u0434\u0430 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043e\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u043b\u043e\u0436\u043d\u0443\u044e \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043e\u0439 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442 \u043c\u043d\u043e\u0433\u043e \u043c\u0435\u0441\u0442\u0430. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u043e\u0433\u0434\u0430 \u043d\u0443\u0436\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044e \u0434\u043b\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043a\u0430\u043a \u043e\u0434\u043d\u043e\u043c \u0438\u0437 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u0432\u044b\u0448\u0435 <\/p>\n<pre><code class=\"python\">from typing import TypeAlias, Callable    func: TypeAlias  = Callable[[float, float], float]  def apply_operation(a: float, b: float, op: func) -&gt; float:   return op(a, b)   add_op: func  = lambda x, y: x + y print(apply_operation(1.2, 2.5, add))<\/code><\/pre>\n<p>\u0411\u0435\u0437 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f <em>TypeAlias <\/em>\u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u043b\u0430 \u0431\u044b \u0433\u0440\u043e\u043c\u043e\u0437\u0434\u043a\u043e\u0439. <\/p>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <em>TypeAlias <\/em>\u0434\u043b\u044f \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u044b\u0445 \u0441\u0441\u044b\u043b\u043e\u043a, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u043b\u044f \u0430\u043d\u043d\u043e\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f <em>JSON <\/em>\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u043e\u0442\u043b\u0438\u0447\u0430\u044e\u0442\u0441\u044f \u043e\u0442 \u043f\u0438\u0442\u043e\u043d\u043e\u0432\u0441\u043a\u0438\u0445. <\/p>\n<pre><code class=\"python\">from typing import TypeAlias, Union  Json: TypeAlias = Union[     str, int, float, bool, None,     dict[str, 'Json'],  # \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u0430\u044f \u0441\u0441\u044b\u043b\u043a\u0430     list['Json'] ]   def parse_json(data: Json) -&gt; None:     print(data)   data: Json = {     \"name\": \"ViacheslavVoo\",     \"scores\": [95, 87, 91],     \"metadata\": {\"active\": True, \"tags\": None}, }  parse_json(data)<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u0441\u0442\u043e\u0438\u0442 \u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e <em>IDE <\/em>\u043c\u043e\u0436\u0435\u0442 \u043d\u0435 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0443 \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0445 \u0442\u0438\u043f\u043e\u0432. \u0414\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u0438\u043b\u0438 \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u044b\u0445 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0439 \u0441\u0442\u043e\u0438\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <strong>mypy<\/strong>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u043a\u0430\u0436\u0435\u0442 \u043e\u0448\u0438\u0431\u043a\u0443. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u0440\u0438 \u043f\u043e\u043f\u044b\u0442\u043a\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <em>tuple<\/em>: <\/p>\n<pre><code class=\"yaml\">error: Dict entry 0 has incompatible type \"str\": \"tuple[int, int, int]\"; expected \"str\": \"str | int | float | dict[str, Json] | list[Json] | None\"  [dict-item] Found 1 error in 1 file (checked 1 source file)<\/code><\/pre>\n<p><strong>NewType<\/strong><\/p>\n<p>\u042d\u0442\u043e\u0442 \u0432\u0438\u0434 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0439 \u0441\u0442\u043e\u0438\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043d\u043e\u0432\u043e\u0433\u043e \u0442\u0438\u043f\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0433\u043e. \u041e\u0441\u043d\u043e\u0432\u043d\u043e\u0435 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 \u0434\u0440\u0443\u0433\u0438\u0445 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0439  &#8212; newtype \u043f\u043e\u0437\u0438\u0446\u0438\u043e\u043d\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u043e\u0431\u043e\u0441\u043e\u0431\u043b\u0435\u043d\u043d\u044b\u0439 \u0432\u0438\u0434 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445. \u0422\u043e \u0435\u0441\u0442\u044c <strong><em>NewType(&#187;, int) != int<\/em><\/strong>, \u0432 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 <em>TypeAlias<\/em>. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u0441\u043c\u044b\u0441\u043b\u043e\u0432\u043e\u0433\u043e \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u044f. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code class=\"python\">from typing import NewType  UserId  = NewType(\"UserId\", int) OrderId  = NewType(\"OrderId\", int)   def get_user(UserId) -&gt; None:   ...   user_id  = UserId(1) order_id  = OrderId(1)  get_user(user_id) get_user(order_id) #mypy \u043f\u043e\u043a\u0430\u0436\u0435\u0442 \u043e\u0448\u0438\u0431\u043a\u0443, \u0442\u0430\u043a \u043a\u0430\u043a UserId \u0438 OrderId  - \u0440\u0430\u0437\u043d\u044b\u0435 \u0442\u0438\u043f\u044b get_user(1) #\u043e\u0448\u0438\u0431\u043a\u0430, \u0442\u0430\u043a \u043a\u0430\u043a \u043e\u0436\u0438\u0434\u0430\u0435\u0442\u0441\u044f UserId<\/code><\/pre>\n<p>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435: \u0434\u043e \u0432\u0435\u0440\u0441\u0438\u0438 Python 3.10 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u0435 <em>NewType <\/em>\u043d\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u043b\u043e \u043d\u0430\u043a\u043b\u0430\u0434\u043d\u044b\u0445 \u0440\u0430\u0441\u0445\u043e\u0434\u043e\u0432, \u043d\u043e \u0432 \u0432\u0435\u0440\u0441\u0438\u0438 3.10 <em>NewType <\/em>\u0441\u0442\u0430\u043b \u043a\u043b\u0430\u0441\u0441\u043e\u043c \u043e\u0431\u0435\u0440\u0442\u043a\u043e\u0439. \u042d\u0442\u043e \u043f\u0440\u0438\u0431\u0430\u0432\u0438\u043b\u043e \u0437\u0430\u0442\u0440\u0430\u0442 \u0432\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f<strong>. \u0412 Python 3.11 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0432\u0435\u0440\u043d\u0443\u043b\u0438 \u043d\u0430 \u0443\u0440\u043e\u0432\u0435\u043d\u044c Python 3.9<\/strong> <\/p>\n<p><strong>Protocol<\/strong><\/p>\n<p><em>Protocol <\/em>\u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u044b \u043d\u0435 \u0445\u043e\u0442\u0438\u0442\u0435 \u044f\u0432\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u0438\u043b\u0438 \u043d\u0435 \u0438\u043c\u0435\u0435\u0442\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0443\u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c\u0441\u044f. \u041f\u043e\u0434 <em>Protocol <\/em>\u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442\u044c \u043b\u044e\u0431\u043e\u0439 \u043a\u043b\u0430\u0441\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u043c\u0435\u0435\u0442 \u043c\u0435\u0442\u043e\u0434 draw. \u0422\u0430\u043a\u0430\u044f \u0448\u0442\u0443\u043a\u0430 \u043a\u0440\u0430\u0439\u043d\u0435 \u043f\u043e\u043b\u0435\u0437\u043d\u0430 \u0434\u043b\u044f \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f <\/p>\n<pre><code class=\"python\">from typing import Protocol   class Drawable(Protocol):     def draw(self) -&gt; None:         ...   class Circle:     def draw(self) -&gt; None:         print(\"draw circle\")      def some_func(self):         print(\"some_func\")   def render(obj: Drawable):     obj.draw()   render(Circle())<\/code><\/pre>\n<p>\u0422\u0438\u043f\u0438\u0437\u0430\u0446\u0438\u044f \u0432 Python \u2014 \u044d\u0442\u043e \u043d\u0435 \u0441\u0442\u0440\u043e\u0433\u0438\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f, \u0430\u00a0\u0441\u043f\u043e\u0441\u043e\u0431 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043a\u043e\u0434 \u043f\u043e\u043d\u044f\u0442\u043d\u0435\u0435, \u043d\u0430\u0434\u0451\u0436\u043d\u0435\u0435 \u0438 \u0443\u0434\u043e\u0431\u043d\u0435\u0435. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 <em>Type hinting<\/em> \u0432 \u0441\u0432\u043e\u0438\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445 \u0438 \u044d\u0442\u043e \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u0441\u044d\u043a\u043e\u043d\u043e\u043c\u0438\u0442\u044c \u0432\u0430\u043c \u0447\u0430\u0441\u044b<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-466018","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/466018","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=466018"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/466018\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=466018"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=466018"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=466018"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}