{"id":336974,"date":"2022-08-12T21:00:19","date_gmt":"2022-08-12T21:00:19","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=336974"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=336974","title":{"rendered":"<span>\u041f\u0440\u0438\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0447\u0438\u0441\u0435\u043b \u0432 python \u0438 mypy \u0438\u043b\u0438 the numeric tower<\/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>\u0415\u0441\u043b\u0438 \u0432\u044b \u043a\u043e\u0433\u0434\u0430-\u043d\u0438\u0431\u0443\u0434\u044c \u0447\u0443\u0432\u0441\u0442\u0432\u043e\u0432\u0430\u043b\u0438, \u0447\u0442\u043e \u0432\u044b \u043f\u043e\u0433\u0440\u044f\u0437\u043b\u0438 \u0432 \u0441\u043e\u0432\u0435\u0449\u0430\u043d\u0438\u044f\u0445 \u0438 \u043e\u0431\u0441\u0443\u0436\u0434\u0435\u043d\u0438\u044f\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u0441\u0451 \u0434\u043b\u044f\u0442\u0441\u044f \u0438 \u0434\u043b\u044f\u0442\u0441\u044f, \u0430 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0432\u0441\u0451 \u043d\u0435\u0442, \u0437\u043d\u0430\u0439\u0442\u0435: \u0432 mypy \u0435\u0441\u0442\u044c 5-\u043b\u0435\u0442\u043d\u0438\u0439 issue, \u043e \u0442\u043e\u043c \u0447\u0442\u043e \u0446\u0435\u043b\u043e\u0435 \u0447\u0438\u0441\u043b\u043e \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0447\u0438\u0441\u043b\u043e\u043c.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/fc6\/741\/f93\/fc6741f93374fb89d5622c6050ea0ae1.png\" width=\"1678\" height=\"1038\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/fc6\/741\/f93\/fc6741f93374fb89d5622c6050ea0ae1.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041f\u043e\u0434\u0441\u043a\u0430\u0437\u043a\u0438 \u0442\u0438\u043f\u043e\u0432 \u0432 python \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0439 \u0442\u0435\u043c\u043e\u0439. \u041b\u044e\u0434\u0438 \u0438\u0437 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0442\u0438\u043f\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u044f\u0437\u044b\u043a\u043e\u0432 \u043d\u0435 \u043f\u043e\u043d\u0438\u043c\u0430\u044e\u0442, \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u044f\u0437\u044b\u043a \u0431\u0435\u0437 \u043d\u0438\u0445, \u0430 \u043f\u043e\u0442\u043e\u043c \u0437\u0430\u0447\u0435\u043c-\u0442\u043e \u0438\u0445 \u043f\u0440\u0438\u043a\u0440\u0443\u0447\u0438\u0432\u0430\u0442\u044c, \u043b\u044e\u0431\u0438\u0442\u0435\u043b\u0438 \u0434\u0438\u043d\u0430\u043c\u0438\u043a\u0438, \u043d\u0435 \u043f\u043e\u043d\u0438\u043c\u0430\u044e\u0442, \u0437\u0430\u0447\u0435\u043c \u0442\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u0440\u0435\u043c\u044f \u043d\u0430 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0442\u0438\u043f\u043e\u0432, \u0435\u0441\u043b\u0438 \u043a\u043e\u0434 \u0438 \u0442\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u0430 \u0430\u043d\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440\u044b \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430 \u0432\u0441\u044f\u043a\u0443\u044e \u0435\u0440\u0443\u043d\u0434\u0443 \u0440\u0443\u0433\u0430\u044e\u0442\u0441\u044f. \u0412 \u0442\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u0430\u043a \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u043d\u0430 python \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u044e\u0442 \u043a\u043e\u0432\u044b\u0440\u044f\u0442\u044c \u0438 \u0434\u0435\u0431\u0430\u0436\u0438\u0442\u044c \u043a\u043e\u0434, \u043f\u044b\u0442\u0430\u044f\u0441\u044c \u043f\u043e\u043d\u044f\u0442\u044c, \u0447\u0442\u043e \u0436\u0435 \u0438\u043c\u0435\u043b \u0432\u0432\u0438\u0434\u0443 \u0430\u0432\u0442\u043e\u0440 \u0438 \u0434\u043e\u043a\u0438\u0434\u044b\u0432\u0430\u044f \u0442\u0438\u043f\u044b, \u0435\u0441\u043b\u0438 \u043f\u043e\u043d\u044f\u0442\u044c \u0443\u0434\u0430\u043b\u043e\u0441\u044c.<\/p>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e, \u043f\u0440\u0438\u043a\u0440\u0443\u0447\u0438\u0432\u0430\u043d\u0438\u0435 \u0442\u0438\u043f\u043e\u0432 \u0438 \u0438\u0445 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0433\u0434\u0435-\u0442\u043e \u0441\u0431\u043e\u043a\u0443 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0438\u043c\u0435\u0435\u0442 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b, \u0434\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u0442\u0430\u043a\u0443\u044e, \u0432\u0440\u043e\u0434\u0435 \u0431\u044b, \u043f\u0440\u043e\u0441\u0442\u0443\u044e \u0442\u0435\u043c\u0443 \u043a\u0430\u043a \u0447\u0438\u0441\u043b\u0430.<\/p>\n<p>\u0412 python \u0435\u0441\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0435 \u0442\u0438\u043f\u044b \u0434\u043b\u044f \u0447\u0438\u0441\u0435\u043b: <a href=\"https:\/\/docs.python.org\/3\/library\/functions.html#int\" rel=\"noopener noreferrer nofollow\">\u0446\u0435\u043b\u044b\u0435<\/a>, \u0432\u0435\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 \u0441 <a href=\"https:\/\/docs.python.org\/3\/library\/functions.html#float\" rel=\"noopener noreferrer nofollow\">\u043f\u043b\u0430\u0432\u0430\u044e\u0449\u0435\u0439<\/a> \u0438 <a href=\"https:\/\/docs.python.org\/3\/library\/decimal.html#decimal.Decimal\" rel=\"noopener noreferrer nofollow\">\u0444\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0439<\/a> \u0442\u043e\u0447\u043a\u043e\u0439, <a href=\"https:\/\/docs.python.org\/3\/library\/fractions.html#fractions.Fraction\" rel=\"noopener noreferrer nofollow\">\u0440\u0430\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0435<\/a> \u0434\u0440\u043e\u0431\u0438 \u0438 \u0434\u0430\u0436\u0435 <a href=\"https:\/\/docs.python.org\/3\/library\/functions.html#complex\" rel=\"noopener noreferrer nofollow\">\u043a\u043e\u043c\u043f\u043b\u0435\u043a\u0441\u043d\u044b\u0435<\/a> \u0447\u0438\u0441\u043b\u0430. \u0414\u0430\u043d\u043d\u044b\u0435 \u0442\u0438\u043f\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0442 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u044b\u0435 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b (ABCs), \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0432 <a href=\"https:\/\/docs.python.org\/3\/library\/numbers.html#the-numeric-tower\" rel=\"noopener noreferrer nofollow\">numeric tower<\/a> (Number, Complex, Real, Rational \u0438 Integral). \u0418 \u0432\u043e\u0442 \u0437\u0434\u0435\u0441\u044c, \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0442\u0441\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b. \u041d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0432\u044b\u0433\u043b\u044f\u0434\u044f\u0442 \u043f\u043e\u043d\u044f\u0442\u043d\u044b\u043c\u0438 \u0438 \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c\u044b\u043c\u0438, <a href=\"https:\/\/peps.python.org\/pep-0484\/#the-numeric-tower\" rel=\"noopener noreferrer nofollow\">\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440<\/a>, \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0449\u0443\u044e float \u0432\u0441\u0435\u0433\u0434\u0430 \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c int, \u0430 \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0449\u0443\u044e complex \u0432\u0441\u0435\u0433\u0434\u0430 \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0438 float, \u0438 int.<\/p>\n<pre><code class=\"python\">def sin(a: float):     print(isinstance(a, float))   def cos(a: complex):     print(isinstance(a, complex))   sin(1)    # \u0432\u044b\u0432\u0435\u0434\u0435\u0442 False cos(4.5)  # \u0442\u043e\u0436\u0435 \u0432\u044b\u0432\u0435\u0434\u0435\u0442 False<\/code><\/pre>\n<p>\u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 mypy \u0432\u044b\u0432\u0435\u0434\u0435\u0442 <code>Success: no issues found in 1 source file.<\/code> \u0418 \u0441 \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f \u0432 \u044d\u0442\u043e\u043c \u0435\u0441\u0442\u044c \u0441\u043c\u044b\u0441\u043b, \u043b\u044e\u0431\u043e\u0435 \u0432\u0435\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u043e\u043c\u043f\u043b\u0435\u043a\u0441\u043d\u044b\u043c, \u0430 \u0446\u0435\u043b\u043e\u0435 \u2014 \u0432\u0435\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c. \u041d\u043e \u0435\u0441\u0442\u044c \u043f\u0443\u0440\u0438\u0441\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0442\u0430\u043a\u043e\u0439 \u043a\u043e\u0434 \u043d\u0435 \u043f\u0440\u043e\u043f\u0443\u0441\u0442\u044f\u0442, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432 rust, \u043d\u0435\u043b\u044c\u0437\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u0446\u0435\u043b\u044b\u0435 \u0447\u0438\u0441\u043b\u0430 \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043e\u0436\u0438\u0434\u0430\u044e\u0449\u0435\u0435 \u0432\u0435\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e.<\/p>\n<pre><code class=\"rust\">fn f(a: f32) { }  fn main() {     f(4) }<\/code><\/pre>\n<pre><code>   Compiling playground v0.0.1 (\/playground) error[E0308]: mismatched types  --> src\/main.rs:6:7   | 6 |     f(4)   |     - ^   |     | |   |     | expected `f32`, found integer   |     | help: use a float literal: `4.0`   |     arguments to this function are incorrect<\/code><\/pre>\n<p>\u0414\u0430 \u0438 \u0432 python \u043a\u0440\u0430\u0441\u0438\u0432\u0430\u044f \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0446\u0438\u044f \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442 \u0442\u0435\u0447\u044c, \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0442\u0438\u043f\u043e\u0432 \u043f\u0440\u043e\u0445\u043e\u0434\u044f\u0442 \u0432 mypy, \u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 <code>isinstance<\/code> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0442 False. \u0422\u043e \u0435\u0441\u0442\u044c \u0442\u0438\u043f \u0432 \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0435 \u0438 \u0432 <code>isinstance<\/code> \u043d\u0435 \u043e\u0434\u043d\u043e \u0438 \u0442\u043e \u0436\u0435, \u0432\u043f\u0440\u043e\u0447\u0435\u043c, \u044d\u0442\u043e \u0434\u0430\u0436\u0435 \u043f\u043e\u043d\u044f\u0442\u043d\u043e, <a href=\"https:\/\/docs.python.org\/3\/library\/abc.html#abc.ABCMeta.__subclasshook__\" rel=\"noopener noreferrer nofollow\">\u0443\u0447\u0438\u0442\u044b\u0432\u0430\u044f<\/a> <code>__subclasshook__<\/code> \u0438 \u0434\u0438\u043d\u0430\u043c\u0438\u0437\u043c \u044f\u0437\u044b\u043a\u0430.<\/p>\n<p>\u0422\u0430\u043a \u0436\u0435 \u0432 python decimal \u0438 float, \u043d\u0435 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0432\u0437\u0430\u0438\u043c\u043e\u0437\u0430\u043c\u0435\u043d\u044f\u0435\u043c\u044b\u043c\u0438 \u0438 \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u044b\u043c\u0438, \u0445\u043e\u0442\u044f \u0441 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u043a\u0438, \u0438 \u0442\u043e, \u0438 \u0434\u0440\u0443\u0433\u043e\u0435 \u2014 \u0432\u0435\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 \u0447\u0438\u0441\u043b\u0430, \u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u0435\u043b\u0438 \u044f\u0437\u044b\u043a\u0430 \u0440\u0435\u0448\u0438\u043b\u0438, \u0447\u0442\u043e \u0441\u043c\u0435\u0448\u0438\u0432\u0430\u0442\u044c \u0432 \u043e\u0434\u043d\u043e\u0439 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0434\u0432\u0430 \u0442\u0438\u043f\u0430 \u043d\u0435 \u0441\u0442\u043e\u0438\u0442, \u0442\u0430\u043a \u043a\u0430\u043a \u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u043a \u043f\u043e\u0442\u0435\u0440\u0435 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438.<\/p>\n<pre><code class=\"python\">>>> Decimal(1) + 2.5 TypeError: unsupported operand type(s) for +: 'decimal.Decimal' and 'float'<\/code><\/pre>\n<p>mypy \u043e\u0431 \u044d\u0442\u043e\u043c \u0437\u043d\u0430\u0435\u0442 \u0438 \u0442\u0430\u043a\u0438\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u043d\u0435 \u0440\u0430\u0437\u0440\u0435\u0448\u0430\u0435\u0442:<\/p>\n<pre><code class=\"bash\">ws.py:15: error: Unsupported operand types for + (\"Decimal\" and \"float\")<\/code><\/pre>\n<p>\u0422\u0430\u043a \u0436\u0435, Decimal \u043d\u0435\u043b\u044c\u0437\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043e\u0436\u0438\u0434\u0430\u044e\u0449\u0443\u044e \u043a\u043e\u043c\u043f\u043b\u0435\u043a\u0441\u043d\u0443\u044e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e, \u0430 \u0446\u0435\u043b\u043e\u0435 \u0447\u0438\u0441\u043b\u043e \u043d\u0435\u043b\u044c\u0437\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043e\u0436\u0438\u0434\u0430\u044e\u0449\u0443\u044e Decimal. \u0425\u043e\u0442\u044f \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0446\u0438\u044f, \u043f\u043e \u0438\u0434\u0435\u0435, \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u0430 \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u0432\u0430\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043e\u0442 \u0442\u043e\u0433\u043e, \u0442\u043e \u043c\u044b \u043f\u043e\u043c\u0435\u043d\u044f\u043b\u0438 \u0432\u0435\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 \u0447\u0438\u0441\u043b\u0430 \u0441 \u043f\u043b\u0430\u0432\u0430\u044e\u0449\u0435\u0439 \u0442\u043e\u0447\u043a\u043e\u0439 \u043d\u0430 \u0447\u0438\u0441\u043b\u0430 \u0441 \u0444\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0439, \u043e\u043d\u0438 \u0432\u0441\u0451 \u0440\u0430\u0432\u043d\u043e \u043e\u0441\u0442\u0430\u044e\u0442\u0441\u044f \u0432\u0435\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c\u0438 \u0438 \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438, \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c\u044b\u0435 \u043d\u0430\u0434 Decimal \u0434\u043e\u043b\u0436\u043d\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0438 \u043d\u0430\u0434 int. \u041d\u043e \u0442\u0430\u043a\u043e\u0439 \u043a\u043e\u0434 mypy \u043d\u0435 \u043f\u0440\u043e\u043f\u0443\u0441\u0442\u0438\u0442.<\/p>\n<pre><code class=\"python\">from decimal import Decimal from numbers import Number   def sin(a: Decimal):     ...   def cos(a: complex):     ...   sin(1) cos(Decimal(1))<\/code><\/pre>\n<pre><code class=\"bash\">ws.py:13: error: Argument 1 to \"sin\" has incompatible type \"int\"; expected \"Decimal\" ws.py:14: error: Argument 1 to \"cos\" has incompatible type \"Decimal\"; expected \"complex\"<\/code><\/pre>\n<p>\u041e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u0437\u0430\u0431\u0430\u0432\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0432 python bool \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u0442\u0441\u044f \u043e\u0442 int.<\/p>\n<pre><code class=\"python\">>>> int.__subclasses__() [bool, ...<\/code><\/pre>\n<pre><code class=\"python\">from decimal import Decimal   def sin(x: float):     pass  sin(Decimal(1))  # ws.py:7: error: Argument 1 to \"sin\" has incompatible type \"Decimal\"; expected \"float\" sin(1==0)        # \u0410 \u044d\u0442\u0438 \u0441\u0442\u0440\u043e\u0447\u043a\u0438 sin(True)        # \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u043f\u0440\u043e\u0445\u043e\u0434\u044f\u0442<\/code><\/pre>\n<p>\u0422\u043e \u0435\u0441\u0442\u044c \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u044c &#171;\u0441\u0438\u043d\u0443\u0441&#187; \u043e\u0442 1 \u043d\u0435\u043b\u044c\u0437\u044f, \u0430 \u043e\u0442 \u0438\u0441\u0442\u0438\u043d\u044b \u2014 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0432\u0435\u0440\u043d\u0451\u043c\u0441\u044f \u043a \u041a\u0414\u041f\u0412. int, Decimal \u0438 float \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f Number.<\/p>\n<pre><code class=\"python\">isinstance(1, Number)             # True isinstance(2.5, Number)           # True isinstance(Decimal(2.5), Number)  # True<\/code><\/pre>\n<p>\u041d\u043e, mypy \u0442\u0430\u043a \u043d\u0435 \u0441\u0447\u0438\u0442\u0430\u0435\u0442. <\/p>\n<pre><code class=\"python\">from decimal import Decimal from numbers import Number   def sin(x: Number):     pass  sin(Decimal(1)) sin(1) sin(2.5) sin(True)<\/code><\/pre>\n<pre><code class=\"bash\">ws.py:8: error: Argument 1 to \"sin\" has incompatible type \"Decimal\"; expected \"Number\" ws.py:9: error: Argument 1 to \"sin\" has incompatible type \"int\"; expected \"Number\" ws.py:10: error: Argument 1 to \"sin\" has incompatible type \"float\"; expected \"Number\" ws.py:11: error: Argument 1 to \"sin\" has incompatible type \"bool\"; expected \"Number\"<\/code><\/pre>\n<p><code>sin(Number(1))<\/code> \u0442\u043e\u0436\u0435 \u043d\u0435 \u043f\u0440\u043e\u0439\u0434\u0451\u0442, \u0442\u0430\u043a \u043a\u0430\u043a Number \u2014 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441.<\/p>\n<p>Python \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u0438\u044f\u0442\u043d\u044b\u0439 \u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u044f\u0437\u044b\u043a, \u043d\u0435\u0434\u0430\u0440\u043e\u043c \u043e\u043d \u0441\u0442\u0430\u043b \u043e\u0434\u043d\u0438\u043c \u0438\u0437 \u0441\u0430\u043c\u044b\u0445 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0445 (\u0430 \u043f\u043e \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043f\u043e\u0434\u0441\u0447\u0451\u0442\u0430\u043c &#8212; \u0441\u0430\u043c\u044b\u043c \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u043c). \u0418 \u043c\u043d\u043e\u0433\u0438\u0435 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u043d\u044b\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u044f, \u043f\u0440\u0438\u043d\u044f\u0442\u044b\u0435 \u043f\u0440\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u044f\u0437\u044b\u043a\u0430 \u0438 \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0442\u043e\u0440\u0430 \u0434\u043e\u0441\u0442\u043e\u0439\u043d\u044b \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u044f. \u041d\u043e, \u0438\u043d\u043e\u0433\u0434\u0430 \u0434\u0430\u0436\u0435 \u0442\u0430\u043a\u0438\u0435 \u043f\u0440\u043e\u0441\u0442\u044b\u0435 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u043a\u0430\u043a \u0447\u0438\u0441\u043b\u0430 \u043f\u0440\u0438\u0432\u043e\u0434\u044f\u0442 \u043a \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u0441\u043b\u043e\u0436\u043d\u044b\u0435 \u0438 \u043d\u0435\u043e\u0434\u043d\u043e\u0437\u043d\u0430\u0447\u043d\u044b\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u044f, \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u0432 \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0431\u0430\u0433\u043e\u0432 \u0438 \u043d\u0435\u043e\u0447\u0435\u0432\u0438\u0434\u043d\u043e\u0441\u0442\u0435\u0439. \u0422\u0430\u043a \u0447\u0442\u043e, \u0435\u0441\u043b\u0438 \u0432\u0434\u0440\u0443\u0433 \u0432\u0430\u0448 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u0438\u043a \u0431\u0443\u0434\u0435\u0442 \u043d\u0435\u0434\u043e\u0432\u043e\u043b\u0435\u043d \u0432\u0430\u0448\u0435\u0439 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u043e\u0439, \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u043f\u044b\u0442\u0430\u0442\u044c\u0441\u044f \u043e\u0442\u043c\u0430\u0437\u0430\u0442\u044c\u0441\u044f \u0442\u0435\u043c, \u0447\u0442\u043e \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0443 \u0432\u0430\u0441 \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0438\u0434\u0435\u0430\u043b\u044c\u043d\u0443\u044e \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u044e \u0442\u0438\u043f\u043e\u0432, \u0434\u0430\u0436\u0435 \u0443 \u0413\u0432\u0438\u0434\u043e \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f.<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/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\/post\/682272\/\"> https:\/\/habr.com\/ru\/post\/682272\/<\/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>\u0415\u0441\u043b\u0438 \u0432\u044b \u043a\u043e\u0433\u0434\u0430-\u043d\u0438\u0431\u0443\u0434\u044c \u0447\u0443\u0432\u0441\u0442\u0432\u043e\u0432\u0430\u043b\u0438, \u0447\u0442\u043e \u0432\u044b \u043f\u043e\u0433\u0440\u044f\u0437\u043b\u0438 \u0432 \u0441\u043e\u0432\u0435\u0449\u0430\u043d\u0438\u044f\u0445 \u0438 \u043e\u0431\u0441\u0443\u0436\u0434\u0435\u043d\u0438\u044f\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u0441\u0451 \u0434\u043b\u044f\u0442\u0441\u044f \u0438 \u0434\u043b\u044f\u0442\u0441\u044f, \u0430 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0432\u0441\u0451 \u043d\u0435\u0442, \u0437\u043d\u0430\u0439\u0442\u0435: \u0432 mypy \u0435\u0441\u0442\u044c 5-\u043b\u0435\u0442\u043d\u0438\u0439 issue, \u043e \u0442\u043e\u043c \u0447\u0442\u043e \u0446\u0435\u043b\u043e\u0435 \u0447\u0438\u0441\u043b\u043e \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0447\u0438\u0441\u043b\u043e\u043c.<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u041f\u043e\u0434\u0441\u043a\u0430\u0437\u043a\u0438 \u0442\u0438\u043f\u043e\u0432 \u0432 python \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0439 \u0442\u0435\u043c\u043e\u0439. \u041b\u044e\u0434\u0438 \u0438\u0437 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0442\u0438\u043f\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u044f\u0437\u044b\u043a\u043e\u0432 \u043d\u0435 \u043f\u043e\u043d\u0438\u043c\u0430\u044e\u0442, \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u044f\u0437\u044b\u043a \u0431\u0435\u0437 \u043d\u0438\u0445, \u0430 \u043f\u043e\u0442\u043e\u043c \u0437\u0430\u0447\u0435\u043c-\u0442\u043e \u0438\u0445 \u043f\u0440\u0438\u043a\u0440\u0443\u0447\u0438\u0432\u0430\u0442\u044c, \u043b\u044e\u0431\u0438\u0442\u0435\u043b\u0438 \u0434\u0438\u043d\u0430\u043c\u0438\u043a\u0438, \u043d\u0435 \u043f\u043e\u043d\u0438\u043c\u0430\u044e\u0442, \u0437\u0430\u0447\u0435\u043c \u0442\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u0440\u0435\u043c\u044f \u043d\u0430 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0442\u0438\u043f\u043e\u0432, \u0435\u0441\u043b\u0438 \u043a\u043e\u0434 \u0438 \u0442\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u0430 \u0430\u043d\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440\u044b \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430 \u0432\u0441\u044f\u043a\u0443\u044e \u0435\u0440\u0443\u043d\u0434\u0443 \u0440\u0443\u0433\u0430\u044e\u0442\u0441\u044f. \u0412 \u0442\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u0430\u043a \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u043d\u0430 python \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u044e\u0442 \u043a\u043e\u0432\u044b\u0440\u044f\u0442\u044c \u0438 \u0434\u0435\u0431\u0430\u0436\u0438\u0442\u044c \u043a\u043e\u0434, \u043f\u044b\u0442\u0430\u044f\u0441\u044c \u043f\u043e\u043d\u044f\u0442\u044c, \u0447\u0442\u043e \u0436\u0435 \u0438\u043c\u0435\u043b \u0432\u0432\u0438\u0434\u0443 \u0430\u0432\u0442\u043e\u0440 \u0438 \u0434\u043e\u043a\u0438\u0434\u044b\u0432\u0430\u044f \u0442\u0438\u043f\u044b, \u0435\u0441\u043b\u0438 \u043f\u043e\u043d\u044f\u0442\u044c \u0443\u0434\u0430\u043b\u043e\u0441\u044c.<\/p>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e, \u043f\u0440\u0438\u043a\u0440\u0443\u0447\u0438\u0432\u0430\u043d\u0438\u0435 \u0442\u0438\u043f\u043e\u0432 \u0438 \u0438\u0445 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0433\u0434\u0435-\u0442\u043e \u0441\u0431\u043e\u043a\u0443 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0438\u043c\u0435\u0435\u0442 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b, \u0434\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u0442\u0430\u043a\u0443\u044e, \u0432\u0440\u043e\u0434\u0435 \u0431\u044b, \u043f\u0440\u043e\u0441\u0442\u0443\u044e \u0442\u0435\u043c\u0443 \u043a\u0430\u043a \u0447\u0438\u0441\u043b\u0430.<\/p>\n<p>\u0412 python \u0435\u0441\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0435 \u0442\u0438\u043f\u044b \u0434\u043b\u044f \u0447\u0438\u0441\u0435\u043b: <a href=\"https:\/\/docs.python.org\/3\/library\/functions.html#int\" rel=\"noopener noreferrer nofollow\">\u0446\u0435\u043b\u044b\u0435<\/a>, \u0432\u0435\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 \u0441 <a href=\"https:\/\/docs.python.org\/3\/library\/functions.html#float\" rel=\"noopener noreferrer nofollow\">\u043f\u043b\u0430\u0432\u0430\u044e\u0449\u0435\u0439<\/a> \u0438 <a href=\"https:\/\/docs.python.org\/3\/library\/decimal.html#decimal.Decimal\" rel=\"noopener noreferrer nofollow\">\u0444\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0439<\/a> \u0442\u043e\u0447\u043a\u043e\u0439, <a href=\"https:\/\/docs.python.org\/3\/library\/fractions.html#fractions.Fraction\" rel=\"noopener noreferrer nofollow\">\u0440\u0430\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0435<\/a> \u0434\u0440\u043e\u0431\u0438 \u0438 \u0434\u0430\u0436\u0435 <a href=\"https:\/\/docs.python.org\/3\/library\/functions.html#complex\" rel=\"noopener noreferrer nofollow\">\u043a\u043e\u043c\u043f\u043b\u0435\u043a\u0441\u043d\u044b\u0435<\/a> \u0447\u0438\u0441\u043b\u0430. \u0414\u0430\u043d\u043d\u044b\u0435 \u0442\u0438\u043f\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0442 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u044b\u0435 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b (ABCs), \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0432 <a href=\"https:\/\/docs.python.org\/3\/library\/numbers.html#the-numeric-tower\" rel=\"noopener noreferrer nofollow\">numeric tower<\/a> (Number, Complex, Real, Rational \u0438 Integral). \u0418 \u0432\u043e\u0442 \u0437\u0434\u0435\u0441\u044c, \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0442\u0441\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b. \u041d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0432\u044b\u0433\u043b\u044f\u0434\u044f\u0442 \u043f\u043e\u043d\u044f\u0442\u043d\u044b\u043c\u0438 \u0438 \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c\u044b\u043c\u0438, <a href=\"https:\/\/peps.python.org\/pep-0484\/#the-numeric-tower\" rel=\"noopener noreferrer nofollow\">\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440<\/a>, \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0449\u0443\u044e float \u0432\u0441\u0435\u0433\u0434\u0430 \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c int, \u0430 \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0449\u0443\u044e complex \u0432\u0441\u0435\u0433\u0434\u0430 \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0438 float, \u0438 int.<\/p>\n<pre><code class=\"python\">def sin(a: float):     print(isinstance(a, float))   def cos(a: complex):     print(isinstance(a, complex))   sin(1)    # \u0432\u044b\u0432\u0435\u0434\u0435\u0442 False cos(4.5)  # \u0442\u043e\u0436\u0435 \u0432\u044b\u0432\u0435\u0434\u0435\u0442 False<\/code><\/pre>\n<p>\u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 mypy \u0432\u044b\u0432\u0435\u0434\u0435\u0442 <code>Success: no issues found in 1 source file.<\/code> \u0418 \u0441 \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f \u0432 \u044d\u0442\u043e\u043c \u0435\u0441\u0442\u044c \u0441\u043c\u044b\u0441\u043b, \u043b\u044e\u0431\u043e\u0435 \u0432\u0435\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u043e\u043c\u043f\u043b\u0435\u043a\u0441\u043d\u044b\u043c, \u0430 \u0446\u0435\u043b\u043e\u0435 \u2014 \u0432\u0435\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c. \u041d\u043e \u0435\u0441\u0442\u044c \u043f\u0443\u0440\u0438\u0441\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0442\u0430\u043a\u043e\u0439 \u043a\u043e\u0434 \u043d\u0435 \u043f\u0440\u043e\u043f\u0443\u0441\u0442\u044f\u0442, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432 rust, \u043d\u0435\u043b\u044c\u0437\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u0446\u0435\u043b\u044b\u0435 \u0447\u0438\u0441\u043b\u0430 \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043e\u0436\u0438\u0434\u0430\u044e\u0449\u0435\u0435 \u0432\u0435\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e.<\/p>\n<pre><code class=\"rust\">fn f(a: f32) { }  fn main() {     f(4) }<\/code><\/pre>\n<pre><code>   Compiling playground v0.0.1 (\/playground) error[E0308]: mismatched types  --> src\/main.rs:6:7   | 6 |     f(4)   |     - ^   |     | |   |     | expected `f32`, found integer   |     | help: use a float literal: `4.0`   |     arguments to this function are incorrect<\/code><\/pre>\n<p>\u0414\u0430 \u0438 \u0432 python \u043a\u0440\u0430\u0441\u0438\u0432\u0430\u044f \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0446\u0438\u044f \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442 \u0442\u0435\u0447\u044c, \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0442\u0438\u043f\u043e\u0432 \u043f\u0440\u043e\u0445\u043e\u0434\u044f\u0442 \u0432 mypy, \u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 <code>isinstance<\/code> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0442 False. \u0422\u043e \u0435\u0441\u0442\u044c \u0442\u0438\u043f \u0432 \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0435 \u0438 \u0432 <code>isinstance<\/code> \u043d\u0435 \u043e\u0434\u043d\u043e \u0438 \u0442\u043e \u0436\u0435, \u0432\u043f\u0440\u043e\u0447\u0435\u043c, \u044d\u0442\u043e \u0434\u0430\u0436\u0435 \u043f\u043e\u043d\u044f\u0442\u043d\u043e, <a href=\"https:\/\/docs.python.org\/3\/library\/abc.html#abc.ABCMeta.__subclasshook__\" rel=\"noopener noreferrer nofollow\">\u0443\u0447\u0438\u0442\u044b\u0432\u0430\u044f<\/a> <code>__subclasshook__<\/code> \u0438 \u0434\u0438\u043d\u0430\u043c\u0438\u0437\u043c \u044f\u0437\u044b\u043a\u0430.<\/p>\n<p>\u0422\u0430\u043a \u0436\u0435 \u0432 python decimal \u0438 float, \u043d\u0435 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0432\u0437\u0430\u0438\u043c\u043e\u0437\u0430\u043c\u0435\u043d\u044f\u0435\u043c\u044b\u043c\u0438 \u0438 \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u044b\u043c\u0438, \u0445\u043e\u0442\u044f \u0441 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u043a\u0438, \u0438 \u0442\u043e, \u0438 \u0434\u0440\u0443\u0433\u043e\u0435 \u2014 \u0432\u0435\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 \u0447\u0438\u0441\u043b\u0430, \u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u0435\u043b\u0438 \u044f\u0437\u044b\u043a\u0430 \u0440\u0435\u0448\u0438\u043b\u0438, \u0447\u0442\u043e \u0441\u043c\u0435\u0448\u0438\u0432\u0430\u0442\u044c \u0432 \u043e\u0434\u043d\u043e\u0439 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0434\u0432\u0430 \u0442\u0438\u043f\u0430 \u043d\u0435 \u0441\u0442\u043e\u0438\u0442, \u0442\u0430\u043a \u043a\u0430\u043a \u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u043a \u043f\u043e\u0442\u0435\u0440\u0435 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438.<\/p>\n<pre><code class=\"python\">>>> Decimal(1) + 2.5 TypeError: unsupported operand type(s) for +: 'decimal.Decimal' and 'float'<\/code><\/pre>\n<p>mypy \u043e\u0431 \u044d\u0442\u043e\u043c \u0437\u043d\u0430\u0435\u0442 \u0438 \u0442\u0430\u043a\u0438\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u043d\u0435 \u0440\u0430\u0437\u0440\u0435\u0448\u0430\u0435\u0442:<\/p>\n<pre><code class=\"bash\">ws.py:15: error: Unsupported operand types for + (\"Decimal\" and \"float\")<\/code><\/pre>\n<p>\u0422\u0430\u043a \u0436\u0435, Decimal \u043d\u0435\u043b\u044c\u0437\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043e\u0436\u0438\u0434\u0430\u044e\u0449\u0443\u044e \u043a\u043e\u043c\u043f\u043b\u0435\u043a\u0441\u043d\u0443\u044e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e, \u0430 \u0446\u0435\u043b\u043e\u0435 \u0447\u0438\u0441\u043b\u043e \u043d\u0435\u043b\u044c\u0437\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043e\u0436\u0438\u0434\u0430\u044e\u0449\u0443\u044e Decimal. \u0425\u043e\u0442\u044f \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0446\u0438\u044f, \u043f\u043e \u0438\u0434\u0435\u0435, \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u0430 \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u0432\u0430\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043e\u0442 \u0442\u043e\u0433\u043e, \u0442\u043e \u043c\u044b \u043f\u043e\u043c\u0435\u043d\u044f\u043b\u0438 \u0432\u0435\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 \u0447\u0438\u0441\u043b\u0430 \u0441 \u043f\u043b\u0430\u0432\u0430\u044e\u0449\u0435\u0439 \u0442\u043e\u0447\u043a\u043e\u0439 \u043d\u0430 \u0447\u0438\u0441\u043b\u0430 \u0441 \u0444\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0439, \u043e\u043d\u0438 \u0432\u0441\u0451 \u0440\u0430\u0432\u043d\u043e \u043e\u0441\u0442\u0430\u044e\u0442\u0441\u044f \u0432\u0435\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c\u0438 \u0438 \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438, \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c\u044b\u0435 \u043d\u0430\u0434 Decimal \u0434\u043e\u043b\u0436\u043d\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0438 \u043d\u0430\u0434 int. \u041d\u043e \u0442\u0430\u043a\u043e\u0439 \u043a\u043e\u0434 mypy \u043d\u0435 \u043f\u0440\u043e\u043f\u0443\u0441\u0442\u0438\u0442.<\/p>\n<pre><code class=\"python\">from decimal import Decimal from numbers import Number   def sin(a: Decimal):     ...   def cos(a: complex):     ...   sin(1) cos(Decimal(1))<\/code><\/pre>\n<pre><code class=\"bash\">ws.py:13: error: Argument 1 to \"sin\" has incompatible type \"int\"; expected \"Decimal\" ws.py:14: error: Argument 1 to \"cos\" has incompatible type \"Decimal\"; expected \"complex\"<\/code><\/pre>\n<p>\u041e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u0437\u0430\u0431\u0430\u0432\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0432 python bool \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u0442\u0441\u044f \u043e\u0442 int.<\/p>\n<pre><code class=\"python\">>>> int.__subclasses__() [bool, ...<\/code><\/pre>\n<pre><code class=\"python\">from decimal import Decimal   def sin(x: float):     pass  sin(Decimal(1))  # ws.py:7: error: Argument 1 to \"sin\" has incompatible type \"Decimal\"; expected \"float\" sin(1==0)        # \u0410 \u044d\u0442\u0438 \u0441\u0442\u0440\u043e\u0447\u043a\u0438 sin(True)        # \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u043f\u0440\u043e\u0445\u043e\u0434\u044f\u0442<\/code><\/pre>\n<p>\u0422\u043e \u0435\u0441\u0442\u044c \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u044c &#171;\u0441\u0438\u043d\u0443\u0441&#187; \u043e\u0442 1 \u043d\u0435\u043b\u044c\u0437\u044f, \u0430 \u043e\u0442 \u0438\u0441\u0442\u0438\u043d\u044b \u2014 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0432\u0435\u0440\u043d\u0451\u043c\u0441\u044f \u043a \u041a\u0414\u041f\u0412. int, Decimal \u0438 float \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f Number.<\/p>\n<pre><code class=\"python\">isinstance(1, Number)             # True isinstance(2.5, Number)           # True isinstance(Decimal(2.5), Number)  # True<\/code><\/pre>\n<p>\u041d\u043e, mypy \u0442\u0430\u043a \u043d\u0435 \u0441\u0447\u0438\u0442\u0430\u0435\u0442. <\/p>\n<pre><code class=\"python\">from decimal import Decimal from numbers import Number   def sin(x: Number):     pass  sin(Decimal(1)) sin(1) sin(2.5) sin(True)<\/code><\/pre>\n<pre><code class=\"bash\">ws.py:8: error: Argument 1 to \"sin\" has incompatible type \"Decimal\"; expected \"Number\" ws.py:9: error: Argument 1 to \"sin\" has incompatible type \"int\"; expected \"Number\" ws.py:10: error: Argument 1 to \"sin\" has incompatible type \"float\"; expected \"Number\" ws.py:11: error: Argument 1 to \"sin\" has incompatible type \"bool\"; expected \"Number\"<\/code><\/pre>\n<p><code>sin(Number(1))<\/code> \u0442\u043e\u0436\u0435 \u043d\u0435 \u043f\u0440\u043e\u0439\u0434\u0451\u0442, \u0442\u0430\u043a \u043a\u0430\u043a Number \u2014 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441.<\/p>\n<p>Python \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u0438\u044f\u0442\u043d\u044b\u0439 \u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u044f\u0437\u044b\u043a, \u043d\u0435\u0434\u0430\u0440\u043e\u043c \u043e\u043d \u0441\u0442\u0430\u043b \u043e\u0434\u043d\u0438\u043c \u0438\u0437 \u0441\u0430\u043c\u044b\u0445 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0445 (\u0430 \u043f\u043e \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043f\u043e\u0434\u0441\u0447\u0451\u0442\u0430\u043c &#8212; \u0441\u0430\u043c\u044b\u043c \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u043c). \u0418 \u043c\u043d\u043e\u0433\u0438\u0435 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u043d\u044b\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u044f, \u043f\u0440\u0438\u043d\u044f\u0442\u044b\u0435 \u043f\u0440\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u044f\u0437\u044b\u043a\u0430 \u0438 \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0442\u043e\u0440\u0430 \u0434\u043e\u0441\u0442\u043e\u0439\u043d\u044b \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u044f. \u041d\u043e, \u0438\u043d\u043e\u0433\u0434\u0430 \u0434\u0430\u0436\u0435 \u0442\u0430\u043a\u0438\u0435 \u043f\u0440\u043e\u0441\u0442\u044b\u0435 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u043a\u0430\u043a \u0447\u0438\u0441\u043b\u0430 \u043f\u0440\u0438\u0432\u043e\u0434\u044f\u0442 \u043a \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u0441\u043b\u043e\u0436\u043d\u044b\u0435 \u0438 \u043d\u0435\u043e\u0434\u043d\u043e\u0437\u043d\u0430\u0447\u043d\u044b\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u044f, \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u0432 \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0431\u0430\u0433\u043e\u0432 \u0438 \u043d\u0435\u043e\u0447\u0435\u0432\u0438\u0434\u043d\u043e\u0441\u0442\u0435\u0439. \u0422\u0430\u043a \u0447\u0442\u043e, \u0435\u0441\u043b\u0438 \u0432\u0434\u0440\u0443\u0433 \u0432\u0430\u0448 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u0438\u043a \u0431\u0443\u0434\u0435\u0442 \u043d\u0435\u0434\u043e\u0432\u043e\u043b\u0435\u043d \u0432\u0430\u0448\u0435\u0439 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u043e\u0439, \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u043f\u044b\u0442\u0430\u0442\u044c\u0441\u044f \u043e\u0442\u043c\u0430\u0437\u0430\u0442\u044c\u0441\u044f \u0442\u0435\u043c, \u0447\u0442\u043e \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0443 \u0432\u0430\u0441 \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0438\u0434\u0435\u0430\u043b\u044c\u043d\u0443\u044e \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u044e \u0442\u0438\u043f\u043e\u0432, \u0434\u0430\u0436\u0435 \u0443 \u0413\u0432\u0438\u0434\u043e \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f.<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/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\/post\/682272\/\"> https:\/\/habr.com\/ru\/post\/682272\/<\/a><br \/><\/br><\/br><\/p>\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-336974","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/336974","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=336974"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/336974\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=336974"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=336974"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=336974"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}