{"id":464521,"date":"2025-06-25T15:08:17","date_gmt":"2025-06-25T15:08:17","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=464521"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=464521","title":{"rendered":"<span>\u041a\u0440\u0443\u0433\u043e\u0432\u043e\u0439 \u0438\u043c\u043f\u043e\u0440\u0442 \u0432 Python: \u043a\u0430\u043a \u043e\u043d \u043b\u043e\u043c\u0430\u0435\u0442 \u043f\u0440\u043e\u0435\u043a\u0442\u044b \u0438 \u043a\u0430\u043a \u0435\u0433\u043e \u043f\u043e\u0431\u0435\u0434\u0438\u0442\u044c<\/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>\u0421\u0435\u0433\u043e\u0434\u043d\u044f \u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043e\u00a0\u0442\u043e\u043c, \u0447\u0442\u043e\u00a0\u0432\u00a0\u043a\u0430\u043a\u043e\u0439\u2011\u0442\u043e \u043c\u043e\u043c\u0435\u043d\u0442 \u0441\u043b\u043e\u0432\u0438\u0442 \u043f\u043e\u0447\u0442\u0438 \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a, \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u0435\u0441\u043b\u0438 \u0432\u044b \u043d\u0435\u00a0\u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0438\u0448\u0435\u0442\u0435 \u0441\u043a\u0440\u0438\u043f\u0442\u044b, \u0430\u00a0\u0441\u0442\u0440\u043e\u0438\u0442\u0435 \u043f\u0440\u043e\u0435\u043a\u0442\u044b\u00a0\u2014 \u0431\u0443\u0434\u044c \u0442\u043e Django, Flask \u0438\u043b\u0438\u00a0\u043a\u0430\u0441\u0442\u043e\u043c\u043d\u0430\u044f \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430 \u0441\u00a0\u0431\u0438\u0437\u043d\u0435\u0441\u2011\u043b\u043e\u0433\u0438\u043a\u043e\u0439 \u0432\u00a0\u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0445 \u0441\u043b\u043e\u044f\u0445. \u0420\u0435\u0447\u044c \u043f\u0440\u043e\u00a0\u043a\u0440\u0443\u0433\u043e\u0432\u044b\u0435 \u0438\u043c\u043f\u043e\u0440\u0442\u044b: \u043e\u043d\u0438 \u043d\u0435\u00a0\u043e\u0431\u044a\u044f\u0432\u043b\u044f\u044e\u0442 \u043e\u00a0\u0441\u0435\u0431\u0435 \u0437\u0430\u0440\u0430\u043d\u0435\u0435, \u043d\u0435\u00a0\u0444\u0435\u0439\u043b\u044f\u0442 \u0432\u0435\u0441\u044c \u043f\u0440\u043e\u0435\u043a\u0442 \u0433\u0440\u043e\u043c\u043a\u043e \u0438 \u0441\u0440\u0430\u0437\u0443, \u043d\u043e\u00a0\u043f\u043e\u0434\u043a\u0440\u0430\u0434\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0438\u0441\u043f\u043e\u0434\u0442\u0438\u0448\u043a\u0430. \u0418 \u0432\u043e\u0442 \u0432\u044b \u0443\u0436\u0435 \u0441\u0438\u0434\u0438\u0442\u0435 \u0441\u00a0\u043e\u0448\u0438\u0431\u043a\u043e\u0439 <code>ImportError: cannot import name ...<\/code> \u0438\u043b\u0438 <code>AttributeError<\/code>, \u0433\u0443\u0433\u043b\u0438\u0442\u0435 \u0447\u0430\u0441\u0430\u043c\u0438, \u0442\u0430\u0441\u0443\u0435\u0442\u0435 \u0438\u043c\u043f\u043e\u0440\u0442\u044b \u0442\u0443\u0434\u0430\u2011\u0441\u044e\u0434\u0430 \u0438 \u043b\u043e\u0432\u0438\u0442\u0435 \u0434\u0435\u0436\u0430\u0432\u044e\u00a0\u2014 \u043a\u0430\u0436\u0435\u0442\u0441\u044f, \u044d\u0442\u043e \u0443\u0436\u0435\u00a0\u0431\u044b\u043b\u043e, \u043d\u043e\u00a0\u0433\u0434\u0435?<\/p>\n<h3>\u041a\u0430\u043a \u043f\u043e\u043d\u044f\u0442\u044c, \u0447\u0442\u043e \u0432\u044b \u043f\u043e\u043f\u0430\u043b\u0438 \u0432 \u043f\u0435\u0442\u043b\u044e<\/h3>\n<p>\u041e\u0431\u044b\u0447\u043d\u043e \u0432\u0441\u0435 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u043d\u0435\u0432\u0438\u043d\u043d\u043e:<\/p>\n<pre><code class=\"python\"># users.py from notifications import send_email  def register(...):     send_email(...)<\/code><\/pre>\n<pre><code class=\"python\"># notifications.py from users import get_user_email   # \u2190 \u0431\u0443\u043c!<\/code><\/pre>\n<p>\u0418\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0442\u043e\u0440 \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u0442 <code>users<\/code>, \u0442\u043e\u0442 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 <code>notifications<\/code>, \u0430 <code>notifications<\/code> \u0441\u043d\u043e\u0432\u0430 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0435\u0449\u0451 \u043d\u0435\u00a0\u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 <code>users<\/code>. \u0418\u0442\u043e\u0433\u00a0\u2014 <code>AttributeError<\/code> \u0438\u043b\u0438 <code>ImportError<\/code>, \u0432\u00a0\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442\u00a0\u0442\u043e\u0433\u043e, \u0432\u00a0\u043a\u0430\u043a\u043e\u0439 \u0444\u0430\u0437\u0435 \u0443\u0441\u043f\u0435\u043b\u043e \u0443\u043f\u0430\u0441\u0442\u044c. <\/p>\n<p>\u041a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0441\u0438\u043c\u043f\u0442\u043e\u043c\u044b:<\/p>\n<ul>\n<li>\n<p><strong>\u0412\u00a0\u0441\u0442\u0435\u043a\u0435 \u0432\u044b\u0437\u043e\u0432\u043e\u0432<\/strong> \u0432\u0438\u0434\u0438\u0442\u0435 \u043e\u0434\u043d\u0443 \u0438 \u0442\u0443\u00a0\u0436\u0435 \u043f\u0430\u0440\u0443 \u0444\u0430\u0439\u043b\u043e\u0432, \u043a\u0440\u0443\u0442\u044f\u0449\u0438\u0445\u0441\u044f \u043a\u0430\u043a\u00a0\u0431\u0435\u043b\u043a\u0430 \u0432\u00a0\u043a\u043e\u043b\u0435\u0441\u0435.<\/p>\n<\/li>\n<li>\n<p><strong>\u041f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435\u2011\u0437\u043e\u043c\u0431\u0438<\/strong>: \u043e\u0431\u044a\u0435\u043a\u0442 \u0443\u0436\u0435 \u0435\u0441\u0442\u044c \u0432 <code>sys.modules<\/code>, \u043d\u043e\u00a0\u043c\u0435\u0442\u043e\u0434\u044b \u0435\u0449\u0451 \u043d\u0435\u00a0\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u044b.<\/p>\n<\/li>\n<li>\n<p><strong>Flask\u2011\u043a\u0435\u0439\u0441<\/strong>: <code>from app import app<\/code> \u0432\u043d\u0443\u0442\u0440\u0438 \u0444\u0430\u0439\u043b\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0435\u0449\u0451 \u0434\u043e\u00a0\u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0441\u0430\u043c\u043e\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f. <\/p>\n<\/li>\n<\/ul>\n<h3>\u041e\u0442\u043a\u0443\u0434\u0430 \u043d\u043e\u0433\u0438 \u2014 \u043a\u0435\u0439\u0441\u044b<\/h3>\n<h4>Flask: \u00abapp factory\u00bb \u0438 Blueprint-\u044b<\/h4>\n<p>\u0412\u00a0\u043a\u043d\u0438\u0433\u0430\u0445 \u043f\u043e\u00a0Flask \u0441\u043e\u0432\u0435\u0442\u0443\u044e\u0442 \u043f\u0430\u0442\u0442\u0435\u0440\u043d <strong>Application Factory<\/strong>: \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>create_app()<\/code> \u043f\u043b\u044e\u0441 Blueprint\u2011\u044b. \u0415\u0441\u043b\u0438\u00a0\u0436\u0435 \u0432\u044b \u0440\u0435\u0448\u0438\u0442\u0435 \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043d\u0430\u00a0\u0443\u0440\u043e\u0432\u043d\u0435 \u043c\u043e\u0434\u0443\u043b\u044f, \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0435 \u00abcannot import name \u201eapp\u201c\u00bb\u00a0\u2014 \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043a\u0440\u0443\u0433\u043e\u0432\u043e\u0439 \u0431\u0443\u043c. \u041b\u0435\u0447\u0435\u043d\u0438\u0435: \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043e\u0431\u044a\u0435\u043a\u0442\u044b (DB, \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u0438) <strong>\u0431\u0435\u0437<\/strong>\u00a0\u0436\u0435\u0441\u0442\u043a\u043e\u0433\u043e \u0438\u043c\u043f\u043e\u0440\u0442\u0430 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0430\u00a0\u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u0438\u0445 \u0432 <code>create_app()<\/code>:<\/p>\n<pre><code class=\"python\"># extensions.py from flask_sqlalchemy import SQLAlchemy db = SQLAlchemy()  # __init__.py def create_app():     from .extensions import db     app = Flask(__name__)     db.init_app(app)     ...     return app<\/code><\/pre>\n<p>\u0422\u0430\u043a \u043c\u044b \u0440\u0430\u0437\u0440\u044b\u0432\u0430\u0435\u043c \u0446\u0435\u043f\u044c: <code>extensions<\/code> \u0437\u043d\u0430\u0435\u0442 \u043e <code>db<\/code>, \u043d\u043e\u00a0\u043d\u0435\u00a0\u043e <code>app<\/code>; <code>app<\/code> \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442 <code>db<\/code> \u043f\u043e\u0437\u0434\u043d\u043e, \u043a\u043e\u0433\u0434\u0430 \u0432\u0441\u0451 \u0433\u043e\u0442\u043e\u0432\u043e. <\/p>\n<h4>Django: \u043c\u043e\u0434\u0435\u043b\u0438, \u0441\u0438\u0433\u043d\u0430\u043b\u044b, \u0441\u0435\u043b\u0444-\u0440\u0435\u0444\u0435\u0440\u0435\u043d\u0441\u044b<\/h4>\n<p>\u0412\u00a0Django \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u044c \u0438\u0437\u00a0\u0434\u0440\u0443\u0433\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438\u00a0\u2014 \u0433\u0440\u0435\u0448\u043e\u043a, \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u0432 <code>signals.py<\/code>. \u041e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u043f\u0440\u0438\u0435\u043c:<\/p>\n<pre><code class=\"python\">from django.apps import apps  User = apps.get_model('auth', 'User')<\/code><\/pre>\n<p>\u0438\u043b\u0438\u00a0\u043f\u0440\u043e\u0441\u0442\u043e \u0441\u0441\u044b\u043b\u0430\u0442\u044c\u0441\u044f \u0441\u0442\u0440\u043e\u043a\u043e\u0439 \u0432 <code>ForeignKey('app.Model')<\/code>. \u0422\u0430\u043a \u043e\u0431\u044a\u0435\u043a\u0442 \u0431\u0443\u0434\u0435\u0442 \u0440\u0435\u0437\u043e\u043b\u0432\u0438\u0442\u044c\u0441\u044f <strong>\u043f\u043e\u0441\u043b\u0435<\/strong> \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u043c\u043e\u0434\u0435\u043b\u0435\u0439, \u0430\u00a0\u043d\u0435\u00a0\u0432\u043e\u00a0\u0432\u0440\u0435\u043c\u044f. <\/p>\n<h4> \u0411\u0438\u0437\u043d\u0435\u0441-\u043b\u043e\u0433\u0438\u043a\u0430: \u00abservice layer\u00bb \u0441\u043f\u0430\u0441\u0435\u0442<\/h4>\n<p>\u041a\u043e\u0433\u0434\u0430 \u00abdomain\u00bb \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u0442 \u00abrepository\u00bb, \u0430\u00a0\u0442\u043e\u0442 \u043e\u0431\u0440\u0430\u0442\u043d\u043e \u00abdomain\u00bb, \u043f\u043e\u0440\u0430 \u0437\u0430\u0432\u0435\u0441\u0442\u0438 <strong>service layer<\/strong> \u0438 \u0432\u044b\u043d\u0435\u0441\u0442\u0438 \u043e\u0431\u0449\u0438\u0435 \u0442\u0438\u043f\u044b \u0432\u00a0\u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u043c\u043e\u0434\u0443\u043b\u044c <code>common<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0435\u00a0\u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043d\u0438 \u043e\u0442\u00a0\u043e\u0434\u043d\u043e\u0433\u043e \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u0441\u043b\u043e\u044f. \u0422\u0430\u043a \u043f\u043e\u0442\u043e\u043a \u0438\u043c\u043f\u043e\u0440\u0442\u043e\u0432 \u0438\u0434\u0435\u0442 \u0441\u0442\u0440\u043e\u0433\u043e \u0441\u0432\u0435\u0440\u0445\u0443 \u0432\u043d\u0438\u0437.<\/p>\n<h3>\u0422\u0440\u0438 \u043a\u0438\u0442\u0430 \u0430\u043d\u0442\u0438-loop \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u044b<\/h3>\n<h4>\u041a\u0438\u0442 \u2116 1. \u041b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0435 \u0438\u043c\u043f\u043e\u0440\u0442\u044b \u2014 \u0431\u044b\u0441\u0442\u0440\u043e \u0438 \u0433\u0440\u044f\u0437\u043d\u043e<\/h4>\n<p>\u0420\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u043d\u043e\u00a0\u0441\u0442\u0440\u0430\u043d\u043d\u043e \u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0441\u044f \u0432\u00a0\u043a\u043e\u0434\u2011\u0440\u0435\u0432\u044c\u044e. \u041f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code class=\"python\">def send_email(...):     from users import get_user_email     ..<\/code><\/pre>\n<p>\u0423\u0431\u0438\u0440\u0430\u0435\u043c \u0446\u0438\u043a\u043b \u043c\u0433\u043d\u043e\u0432\u0435\u043d\u043d\u043e \u0438 \u044d\u043a\u043e\u043d\u043e\u043c\u0438\u043c \u0432\u0440\u0435\u043c\u044f \u0441\u0442\u0430\u0440\u0442\u0430.<\/p>\n<p>\u041d\u043e\u00a0\u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043b\u0435\u0433\u043a\u043e \u0437\u0430\u0431\u044b\u0442\u044c \u043e\u00a0\u043d\u0438\u0445, \u0441\u043b\u043e\u0436\u043d\u043e \u043c\u043e\u043a\u0430\u0442\u044c \u0432\u00a0\u0442\u0435\u0441\u0442\u0430\u0445. \u0415\u0441\u043b\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0447\u0430\u0441\u0442\u043e, \u0438\u043c\u043f\u043e\u0440\u0442 \u0431\u0443\u0434\u0435\u0442 \u0432\u0430\u043b\u0438\u0442\u044c \u043a\u0435\u0448\u2006\u2011 \u043b\u0435\u0447\u0438\u0442\u0441\u044f \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0435\u043c: <code>if 'users' not in sys.modules: ...<\/code>.<\/p>\n<h4>\u041a\u0438\u0442 \u2116 2. Lazy imports \u043f\u043e PEP 690 <\/h4>\n<p>\u0421\u00a0\u0432\u044b\u0445\u043e\u0434\u043e\u043c 3.13\u00a0\u0432\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0439 \u0444\u043b\u0430\u0433 (\u0438\u043b\u0438 <code>from <strong>future<\/strong> import lazy_imports<\/code>)\u00a0\u2014 \u043c\u043e\u0434\u0443\u043b\u0438 \u0441\u0442\u0430\u043d\u043e\u0432\u044f\u0442\u0441\u044f \u00ab\u0437\u043e\u043c\u0431\u0438\u2011\u043f\u0440\u043e\u043a\u0441\u0430\u043c\u0438\u00bb \u0438 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u043f\u0440\u0438\u00a0\u043f\u0435\u0440\u0432\u043e\u043c \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0438. \u0426\u0438\u043a\u043b \u0440\u0430\u0437\u0440\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0441\u0430\u043c, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e\u00a0\u043a\u043e\u0434, \u0442\u0440\u0435\u0431\u0443\u044e\u0449\u0438\u0439 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c, \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u0432\u0430\u043d <strong>\u043f\u043e\u0441\u043b\u0435<\/strong> \u043f\u043e\u043b\u043d\u043e\u0439 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438.<\/p>\n<p>\u041b\u0435\u043d\u0438\u0432\u044b\u0435 \u0438\u043c\u043f\u043e\u0440\u0442\u044b + Cinder \u0434\u0430\u044e\u0442 \u221240% \u043a\u00a0\u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0434\u043e\u00a0\u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0431\u0430\u0442\u0447\u0430 \u0432\u00a0ML\u2011\u0432\u043e\u0440\u043a\u0444\u043b\u043e\u0443\u00a0\u2014 \u0442\u0430\u043a \u0447\u0442\u043e\u00a0\u043f\u0440\u043e\u0444\u0438\u0442 \u043e\u0449\u0443\u0442\u0438\u043c. <\/p>\n<h4>\u041a\u0438\u0442 \u2116 3. \u0421\u0442\u0440\u043e\u0433\u043e\u0435 \u0440\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u0435 \u0441\u043b\u043e\u0451\u0432<\/h4>\n<ul>\n<li>\n<p><code>api<\/code> \u2192 <code>service<\/code> \u2192 <code>repository<\/code> \u2192 <code>drivers<\/code><\/p>\n<\/li>\n<li>\n<p>\u00ab\u043d\u0438\u0437\u00bb \u043d\u0438\u043a\u043e\u0433\u0434\u0430 \u043d\u0435\u00a0\u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u0442 \u00ab\u0432\u0435\u0440\u0445\u00bb.<\/p>\n<\/li>\n<li>\n<p>\u041e\u0431\u0449\u0438\u0435 enum \u0438 \u0434\u0430\u0442\u0430\u043a\u043b\u0430\u0441\u0441\u044b\u00a0\u2014 \u0432 <code>domain<\/code> \u0438\u043b\u0438 <code>common<\/code>.<\/p>\n<\/li>\n<\/ul>\n<p>\u0421\u0445\u0435\u043c\u0430 \u0431\u0430\u043d\u0430\u043b\u044c\u043d\u0430, \u043d\u043e\u00a0\u0437\u0430\u0442\u044b\u043a\u0430\u0435\u0442 90% \u043a\u0440\u0443\u0433\u043e\u0432\u044b\u0445 \u043e\u0433\u0440\u0435\u0445\u043e\u0432.<\/p>\n<h3>importlib: \u043a\u043e\u0433\u0434\u0430 \u043e\u0447\u0435\u043d\u044c \u043d\u0430\u0434\u043e<\/h3>\n<pre><code class=\"python\">import importlib  def load_plugin(name: str):     return importlib.import_module(f'app.plugins.{name}')<\/code><\/pre>\n<p>\u041f\u043e\u0434\u0433\u0440\u0443\u0436\u0430\u0435\u043c \u043c\u043e\u0434\u0443\u043b\u0438 \u043f\u043e\u00a0\u0441\u0442\u0440\u043e\u043a\u0435, \u0438\u0437\u0431\u0435\u0433\u0430\u044f \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0446\u0438\u043a\u043b\u0430. \u041e\u0442\u043b\u0438\u0447\u043d\u0430\u044f \u0442\u043e\u0447\u043a\u0430 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f \u0434\u043b\u044f\u00a0\u0441\u0438\u0441\u0442\u0435\u043c \u043f\u043b\u0430\u0433\u0438\u043d\u043e\u0432.<\/p>\n<p>\u0418\u043d\u043e\u0433\u0434\u0430 \u043c\u043e\u0434\u0443\u043b\u044c \u0443\u0436\u0435 \u0435\u0441\u0442\u044c \u0432 <code>sys.modules<\/code>, \u043d\u043e\u00a0\u044d\u043a\u0441\u043f\u043e\u0440\u0442 \u043d\u0435\u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u0438\u0437\u2011\u0437\u0430 \u0440\u0430\u043d\u043d\u0435\u0433\u043e \u043f\u0430\u0434\u0435\u043d\u0438\u044f. \u0422\u043e\u0433\u0434\u0430:<\/p>\n<pre><code class=\"python\">module = importlib.reload(sys.modules['users'])<\/code><\/pre>\n<p>\u041d\u0435\u00a0\u0441\u0430\u043c\u044b\u0439 \u0447\u0438\u0441\u0442\u044b\u0439 \u043f\u0430\u0442\u0442\u0435\u0440\u043d, \u043d\u043e\u00a0\u0441\u043f\u0430\u0441\u0430\u0435\u0442.<\/p>\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u0435\u0449\u0451 \u0441\u0438\u0434\u0438\u0442\u0435 \u043d\u0430 3.10\u20133.12, \u043f\u0438\u0448\u0435\u043c \u0441\u0432\u043e\u0439 \u00ab\u043b\u0435\u043d\u0438\u0432\u044b\u0439\u00bb \u0437\u0430\u0433\u0440\u0443\u0437\u0447\u0438\u043a (\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f Python \u043f\u0440\u0438\u0432\u0435\u043b\u0430 \u0448\u0438\u043a\u0430\u0440\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440): <\/p>\n<pre><code class=\"python\">import importlib.util as iu import sys, types  def lazy_import(name):     spec = iu.find_spec(name)     spec.loader = iu.LazyLoader(spec.loader)     module = iu.module_from_spec(spec)     sys.modules[name] = module     spec.loader.exec_module(module)     return module<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c <code>lazy_import(\"numpy\")<\/code> \u043d\u0435\u00a0\u043f\u0440\u043e\u0433\u0440\u0443\u0437\u0438\u0442 200\u00a0\u041c\u0411 C\u2011\u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0439, \u043f\u043e\u043a\u0430 \u0432\u044b \u043d\u0435\u00a0\u0434\u0451\u0440\u043d\u0435\u0442\u0435 <code>numpy.array<\/code>.<\/p>\n<h3>\u041a\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0435 \u043b\u043e\u043c\u0430\u0435\u0442\u0441\u044f<\/h3>\n<h4>Enum-\u044b \u0438 DTO \u2014 \u0432 \u043e\u0434\u043d\u043e\u043c \u043c\u0435\u0441\u0442\u0435<\/h4>\n<pre><code class=\"python\"># common\/types.py from enum import Enum class Role(str, Enum):     ADMIN = 'admin'     USER = 'user'<\/code><\/pre>\n<p><code>users<\/code>, <code>auth<\/code>, <code>payments<\/code> \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u044e\u0442 \u0442\u043e\u043b\u044c\u043a\u043e <code>Role<\/code>, \u043d\u043e\u00a0\u043d\u0435\u00a0\u0434\u0440\u0443\u0433 \u0434\u0440\u0443\u0433\u0430.<\/p>\n<h4>\u0424\u0430\u0431\u0440\u0438\u043a\u0438 \u0432\u043c\u0435\u0441\u0442\u043e \u043f\u0440\u044f\u043c\u044b\u0445 \u0441\u0441\u044b\u043b\u043e\u043a<\/h4>\n<pre><code class=\"r\"># services\/email_service.py def get_email_sender():     from adapters.smtp import SmtpSender     return SmtpSender(...)<\/code><\/pre>\n<p>\u0422\u0435\u0441\u0442 \u043b\u0435\u0433\u043a\u043e \u043f\u043e\u0434\u043c\u0435\u043d\u0438\u0442\u044c \u0447\u0435\u0440\u0435\u0437 monkey\u2011patch:<\/p>\n<pre><code class=\"python\">monkeypatch.setattr(email_service, 'get_email_sender', FakeSender)<\/code><\/pre>\n<h4>\u041f\u0430\u0442\u0442\u0435\u0440\u043d \u00ab\u0432\u0435\u0440\u0445\u043d\u0438\u0439 \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u2014 \u0442\u043e\u043b\u044c\u043a\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b\u00bb<\/h4>\n<pre><code># repos\/__init__.py from .base import AbstractRepo<\/code><\/pre>\n<p><code>service.py<\/code> \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u0442 <code>AbstractRepo<\/code>, \u0430\u00a0\u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f <code>PgRepo<\/code> \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 DI\u2011\u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, repo \u00ab\u0437\u043d\u0430\u0435\u0442\u00bb \u043e\u00a0service? \u041d\u0435\u0442, \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430\u043e\u0431\u043e\u0440\u043e\u0442.<\/p>\n<h3>\u041e\u0441\u0442\u0440\u044b\u0435 \u0443\u0433\u043e\u043b\u043a\u0438<\/h3>\n<ol>\n<li>\n<p><strong>\u00ab\u041b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0435 \u0438\u043c\u043f\u043e\u0440\u0442\u044b\u00a0\u2014 \u044d\u0442\u043e \u043d\u0435\u043a\u0440\u0430\u0441\u0438\u0432\u043e\u00bb<\/strong>. \u0421\u043e\u0433\u043b\u0430\u0441\u0435\u043d, \u043d\u043e\u00a0\u043a\u043e\u0433\u0434\u0430 \u0433\u043e\u0440\u0438\u0442, \u0441\u0442\u043e\u0438\u0442 \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u0440\u0430\u0431\u043e\u0447\u0435\u0435 \u0438 \u0443\u0440\u043e\u0434\u043b\u0438\u0432\u043e\u0435\u00bb \u0432\u043c\u0435\u0441\u0442\u043e \u00ab\u043a\u0440\u0430\u0441\u0438\u0432\u043e\u0435, \u043d\u043e\u00a0\u043b\u0435\u0436\u0438\u0442\u00bb.<\/p>\n<\/li>\n<li>\n<p><strong>Lazy imports \u0441\u043a\u0440\u044b\u0432\u0430\u044e\u0442 \u043e\u0448\u0438\u0431\u043a\u0438<\/strong>: \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0432\u0441\u043f\u043b\u044b\u0432\u0430\u044e\u0442 \u043d\u0435\u00a0\u043d\u0430\u00a0\u0441\u0442\u0430\u0440\u0442\u0435, \u0430\u00a0\u0432\u00a0\u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442. \u041b\u043e\u0433\u0438\u0440\u0443\u0439\u0442\u0435 <code>importlib.invalidate_caches()<\/code> \u043d\u0430\u00a0CI \u0438 \u0433\u043e\u043d\u044f\u0439\u0442\u0435 <code>pytest -Werror<\/code>.<\/p>\n<\/li>\n<li>\n<p><strong>\u0421\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0430\u043d\u0430\u043b\u0438\u0437<\/strong> (mypy, pylint) \u043c\u043e\u0436\u0435\u0442 \u043d\u0435\u00a0\u0432\u0438\u0434\u0435\u0442\u044c \u0434\u0438\u043d\u0430\u043c\u0438\u043a\u0443. \u0420\u0435\u0448\u0435\u043d\u0438\u0435\u00a0\u2014 <code>typing.TYPE_CHECKING<\/code> \u0438 \u043f\u0441\u0435\u0432\u0434\u043e\u2011\u0438\u043c\u043f\u043e\u0440\u0442:<\/p>\n<pre><code>from typing import TYPE_CHECKING if TYPE_CHECKING:     from service import ImportantClass<\/code><\/pre>\n<\/li>\n<li>\n<p><strong>\u0420\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433 \u0441\u0442\u043e \u0441\u0442\u0440\u043e\u043a vs. \u0440\u0443\u0447\u043a\u0430 <\/strong><code><strong>reload<\/strong><\/code>. \u042f \u0437\u0430\u00a0\u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433: \u0434\u043e\u043b\u0433\u043e\u0441\u0440\u043e\u0447\u043d\u043e \u0434\u0435\u0448\u0435\u0432\u043b\u0435.<\/p>\n<\/li>\n<\/ol>\n<hr\/>\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u0434\u043e\u0447\u0438\u0442\u0430\u043b\u0438 \u0434\u043e \u044d\u0442\u043e\u0433\u043e \u043c\u0435\u0441\u0442\u0430, \u0441\u043a\u043e\u0440\u0435\u0435 \u0432\u0441\u0435\u0433\u043e, \u0443\u0436\u0435 \u0441\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u043b\u0438\u0441\u044c \u0441 \u043a\u0440\u0443\u0433\u043e\u0432\u044b\u043c\u0438 \u0438\u043c\u043f\u043e\u0440\u0442\u0430\u043c\u0438 \u0438\u043b\u0438 \u043a\u0430\u043a \u043c\u0438\u043d\u0438\u043c\u0443\u043c \u0441 \u0431\u043e\u043b\u044c\u044e \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u043d\u044b\u0445 \u043a\u043e\u0441\u0442\u044b\u043b\u0435\u0439. \u0410 \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u044c\u0442\u0435: \u0432\u0430\u0448 \u043a\u043e\u0434 \u043d\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0435 \u043b\u043e\u043c\u0430\u0435\u0442\u0441\u044f \u2014 \u043e\u043d \u0443\u0441\u0442\u043e\u0439\u0447\u0438\u0432, \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u0443\u0435\u043c \u0438 \u0433\u043e\u0442\u043e\u0432 \u043a \u0440\u043e\u0441\u0442\u0443 \u043a\u043e\u043c\u0430\u043d\u0434\u044b.<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u043a \u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u0438\u0439\u0442\u0438 \u2014 \u0441\u0442\u043e\u0438\u0442 \u043d\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u0433\u0443\u0433\u043b\u0438\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0438, \u0430 \u043a\u043e\u043f\u0430\u0442\u044c \u0433\u043b\u0443\u0431\u0436\u0435. \u041c\u044b \u0432 OTUS \u043a\u0430\u043a \u0440\u0430\u0437 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0441\u0434\u0435\u043b\u0430\u043b\u0438 \u0434\u0432\u0430 \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u0445 \u0443\u0440\u043e\u043a\u0430. \u0411\u0435\u0437 \u00ab\u0432\u043e\u0434\u044b\u00bb, \u0441 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u043e\u0439 \u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0439:<\/p>\n<ul>\n<li>\n<p><a href=\"https:\/\/otus.pw\/92WI\/\" rel=\"noopener noreferrer nofollow\"><strong>\u041e\u0441\u043d\u043e\u0432\u044b \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0439 \u0442\u0438\u043f\u043e\u0432 \u0432 Python<\/strong><\/a> \u2014 <em>26 \u0438\u044e\u043d\u044f \u0432 20:00<\/em><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/otus.pw\/t0Dm\/\" rel=\"noopener noreferrer nofollow\"><strong>\u0428\u0438\u043a, \u0431\u043b\u0435\u0441\u043a, \u0447\u0438\u0441\u0442\u043e\u0442\u0430: clean architecture \u0432 Python<\/strong><\/a> \u2014 <em>1 \u0438\u044e\u043b\u044f \u0432 20:00<\/em><\/p>\n<\/li>\n<\/ul>\n<p>\u0410\u00a0\u0435\u0441\u043b\u0438 \u043f\u043e\u0441\u043b\u0435 \u0443\u0440\u043e\u043a\u043e\u0432 \u0432\u044b \u0437\u0430\u0445\u043e\u0442\u0438\u0442\u0435 \u0434\u0432\u0438\u0433\u0430\u0442\u044c\u0441\u044f \u0434\u0430\u043b\u044c\u0448\u0435\u00a0\u2014 \u0437\u0430\u0433\u043b\u044f\u043d\u0438\u0442\u0435 \u043d\u0430\u00a0\u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443 \u043a\u0443\u0440\u0441\u0430 <a href=\"https:\/\/otus.pw\/sQXuF\/\" rel=\"noopener noreferrer nofollow\">\u00ab\u0421\u043f\u0435\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f Python Developer\u00bb<\/a>. \u041c\u044b \u043f\u043e\u0441\u0442\u0430\u0440\u0430\u043b\u0438\u0441\u044c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u043f\u0440\u0438\u043a\u043b\u0430\u0434\u043d\u043e\u0439 \u0438 \u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u043d\u0430\u00a0\u0440\u0435\u0430\u043b\u044c\u043d\u0443\u044e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0443.<\/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\/919676\/\"> https:\/\/habr.com\/ru\/articles\/919676\/<\/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>\u0421\u0435\u0433\u043e\u0434\u043d\u044f \u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043e\u00a0\u0442\u043e\u043c, \u0447\u0442\u043e\u00a0\u0432\u00a0\u043a\u0430\u043a\u043e\u0439\u2011\u0442\u043e \u043c\u043e\u043c\u0435\u043d\u0442 \u0441\u043b\u043e\u0432\u0438\u0442 \u043f\u043e\u0447\u0442\u0438 \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a, \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u0435\u0441\u043b\u0438 \u0432\u044b \u043d\u0435\u00a0\u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0438\u0448\u0435\u0442\u0435 \u0441\u043a\u0440\u0438\u043f\u0442\u044b, \u0430\u00a0\u0441\u0442\u0440\u043e\u0438\u0442\u0435 \u043f\u0440\u043e\u0435\u043a\u0442\u044b\u00a0\u2014 \u0431\u0443\u0434\u044c \u0442\u043e Django, Flask \u0438\u043b\u0438\u00a0\u043a\u0430\u0441\u0442\u043e\u043c\u043d\u0430\u044f \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430 \u0441\u00a0\u0431\u0438\u0437\u043d\u0435\u0441\u2011\u043b\u043e\u0433\u0438\u043a\u043e\u0439 \u0432\u00a0\u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0445 \u0441\u043b\u043e\u044f\u0445. \u0420\u0435\u0447\u044c \u043f\u0440\u043e\u00a0\u043a\u0440\u0443\u0433\u043e\u0432\u044b\u0435 \u0438\u043c\u043f\u043e\u0440\u0442\u044b: \u043e\u043d\u0438 \u043d\u0435\u00a0\u043e\u0431\u044a\u044f\u0432\u043b\u044f\u044e\u0442 \u043e\u00a0\u0441\u0435\u0431\u0435 \u0437\u0430\u0440\u0430\u043d\u0435\u0435, \u043d\u0435\u00a0\u0444\u0435\u0439\u043b\u044f\u0442 \u0432\u0435\u0441\u044c \u043f\u0440\u043e\u0435\u043a\u0442 \u0433\u0440\u043e\u043c\u043a\u043e \u0438 \u0441\u0440\u0430\u0437\u0443, \u043d\u043e\u00a0\u043f\u043e\u0434\u043a\u0440\u0430\u0434\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0438\u0441\u043f\u043e\u0434\u0442\u0438\u0448\u043a\u0430. \u0418 \u0432\u043e\u0442 \u0432\u044b \u0443\u0436\u0435 \u0441\u0438\u0434\u0438\u0442\u0435 \u0441\u00a0\u043e\u0448\u0438\u0431\u043a\u043e\u0439 <code>ImportError: cannot import name ...<\/code> \u0438\u043b\u0438 <code>AttributeError<\/code>, \u0433\u0443\u0433\u043b\u0438\u0442\u0435 \u0447\u0430\u0441\u0430\u043c\u0438, \u0442\u0430\u0441\u0443\u0435\u0442\u0435 \u0438\u043c\u043f\u043e\u0440\u0442\u044b \u0442\u0443\u0434\u0430\u2011\u0441\u044e\u0434\u0430 \u0438 \u043b\u043e\u0432\u0438\u0442\u0435 \u0434\u0435\u0436\u0430\u0432\u044e\u00a0\u2014 \u043a\u0430\u0436\u0435\u0442\u0441\u044f, \u044d\u0442\u043e \u0443\u0436\u0435\u00a0\u0431\u044b\u043b\u043e, \u043d\u043e\u00a0\u0433\u0434\u0435?<\/p>\n<h3>\u041a\u0430\u043a \u043f\u043e\u043d\u044f\u0442\u044c, \u0447\u0442\u043e \u0432\u044b \u043f\u043e\u043f\u0430\u043b\u0438 \u0432 \u043f\u0435\u0442\u043b\u044e<\/h3>\n<p>\u041e\u0431\u044b\u0447\u043d\u043e \u0432\u0441\u0435 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u043d\u0435\u0432\u0438\u043d\u043d\u043e:<\/p>\n<pre><code class=\"python\"># users.py from notifications import send_email  def register(...):     send_email(...)<\/code><\/pre>\n<pre><code class=\"python\"># notifications.py from users import get_user_email   # \u2190 \u0431\u0443\u043c!<\/code><\/pre>\n<p>\u0418\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0442\u043e\u0440 \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u0442 <code>users<\/code>, \u0442\u043e\u0442 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 <code>notifications<\/code>, \u0430 <code>notifications<\/code> \u0441\u043d\u043e\u0432\u0430 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0435\u0449\u0451 \u043d\u0435\u00a0\u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 <code>users<\/code>. \u0418\u0442\u043e\u0433\u00a0\u2014 <code>AttributeError<\/code> \u0438\u043b\u0438 <code>ImportError<\/code>, \u0432\u00a0\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442\u00a0\u0442\u043e\u0433\u043e, \u0432\u00a0\u043a\u0430\u043a\u043e\u0439 \u0444\u0430\u0437\u0435 \u0443\u0441\u043f\u0435\u043b\u043e \u0443\u043f\u0430\u0441\u0442\u044c. <\/p>\n<p>\u041a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0441\u0438\u043c\u043f\u0442\u043e\u043c\u044b:<\/p>\n<ul>\n<li>\n<p><strong>\u0412\u00a0\u0441\u0442\u0435\u043a\u0435 \u0432\u044b\u0437\u043e\u0432\u043e\u0432<\/strong> \u0432\u0438\u0434\u0438\u0442\u0435 \u043e\u0434\u043d\u0443 \u0438 \u0442\u0443\u00a0\u0436\u0435 \u043f\u0430\u0440\u0443 \u0444\u0430\u0439\u043b\u043e\u0432, \u043a\u0440\u0443\u0442\u044f\u0449\u0438\u0445\u0441\u044f \u043a\u0430\u043a\u00a0\u0431\u0435\u043b\u043a\u0430 \u0432\u00a0\u043a\u043e\u043b\u0435\u0441\u0435.<\/p>\n<\/li>\n<li>\n<p><strong>\u041f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435\u2011\u0437\u043e\u043c\u0431\u0438<\/strong>: \u043e\u0431\u044a\u0435\u043a\u0442 \u0443\u0436\u0435 \u0435\u0441\u0442\u044c \u0432 <code>sys.modules<\/code>, \u043d\u043e\u00a0\u043c\u0435\u0442\u043e\u0434\u044b \u0435\u0449\u0451 \u043d\u0435\u00a0\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u044b.<\/p>\n<\/li>\n<li>\n<p><strong>Flask\u2011\u043a\u0435\u0439\u0441<\/strong>: <code>from app import app<\/code> \u0432\u043d\u0443\u0442\u0440\u0438 \u0444\u0430\u0439\u043b\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0435\u0449\u0451 \u0434\u043e\u00a0\u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0441\u0430\u043c\u043e\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f. <\/p>\n<\/li>\n<\/ul>\n<h3>\u041e\u0442\u043a\u0443\u0434\u0430 \u043d\u043e\u0433\u0438 \u2014 \u043a\u0435\u0439\u0441\u044b<\/h3>\n<h4>Flask: \u00abapp factory\u00bb \u0438 Blueprint-\u044b<\/h4>\n<p>\u0412\u00a0\u043a\u043d\u0438\u0433\u0430\u0445 \u043f\u043e\u00a0Flask \u0441\u043e\u0432\u0435\u0442\u0443\u044e\u0442 \u043f\u0430\u0442\u0442\u0435\u0440\u043d <strong>Application Factory<\/strong>: \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>create_app()<\/code> \u043f\u043b\u044e\u0441 Blueprint\u2011\u044b. \u0415\u0441\u043b\u0438\u00a0\u0436\u0435 \u0432\u044b \u0440\u0435\u0448\u0438\u0442\u0435 \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043d\u0430\u00a0\u0443\u0440\u043e\u0432\u043d\u0435 \u043c\u043e\u0434\u0443\u043b\u044f, \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0435 \u00abcannot import name \u201eapp\u201c\u00bb\u00a0\u2014 \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043a\u0440\u0443\u0433\u043e\u0432\u043e\u0439 \u0431\u0443\u043c. \u041b\u0435\u0447\u0435\u043d\u0438\u0435: \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043e\u0431\u044a\u0435\u043a\u0442\u044b (DB, \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u0438) <strong>\u0431\u0435\u0437<\/strong>\u00a0\u0436\u0435\u0441\u0442\u043a\u043e\u0433\u043e \u0438\u043c\u043f\u043e\u0440\u0442\u0430 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0430\u00a0\u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u0438\u0445 \u0432 <code>create_app()<\/code>:<\/p>\n<pre><code class=\"python\"># extensions.py from flask_sqlalchemy import SQLAlchemy db = SQLAlchemy()  # __init__.py def create_app():     from .extensions import db     app = Flask(__name__)     db.init_app(app)     ...     return app<\/code><\/pre>\n<p>\u0422\u0430\u043a \u043c\u044b \u0440\u0430\u0437\u0440\u044b\u0432\u0430\u0435\u043c \u0446\u0435\u043f\u044c: <code>extensions<\/code> \u0437\u043d\u0430\u0435\u0442 \u043e <code>db<\/code>, \u043d\u043e\u00a0\u043d\u0435\u00a0\u043e <code>app<\/code>; <code>app<\/code> \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442 <code>db<\/code> \u043f\u043e\u0437\u0434\u043d\u043e, \u043a\u043e\u0433\u0434\u0430 \u0432\u0441\u0451 \u0433\u043e\u0442\u043e\u0432\u043e. <\/p>\n<h4>Django: \u043c\u043e\u0434\u0435\u043b\u0438, \u0441\u0438\u0433\u043d\u0430\u043b\u044b, \u0441\u0435\u043b\u0444-\u0440\u0435\u0444\u0435\u0440\u0435\u043d\u0441\u044b<\/h4>\n<p>\u0412\u00a0Django \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u044c \u0438\u0437\u00a0\u0434\u0440\u0443\u0433\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438\u00a0\u2014 \u0433\u0440\u0435\u0448\u043e\u043a, \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u0432 <code>signals.py<\/code>. \u041e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u043f\u0440\u0438\u0435\u043c:<\/p>\n<pre><code class=\"python\">from django.apps import apps  User = apps.get_model('auth', 'User')<\/code><\/pre>\n<p>\u0438\u043b\u0438\u00a0\u043f\u0440\u043e\u0441\u0442\u043e \u0441\u0441\u044b\u043b\u0430\u0442\u044c\u0441\u044f \u0441\u0442\u0440\u043e\u043a\u043e\u0439 \u0432 <code>ForeignKey('app.Model')<\/code>. \u0422\u0430\u043a \u043e\u0431\u044a\u0435\u043a\u0442 \u0431\u0443\u0434\u0435\u0442 \u0440\u0435\u0437\u043e\u043b\u0432\u0438\u0442\u044c\u0441\u044f <strong>\u043f\u043e\u0441\u043b\u0435<\/strong> \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u043c\u043e\u0434\u0435\u043b\u0435\u0439, \u0430\u00a0\u043d\u0435\u00a0\u0432\u043e\u00a0\u0432\u0440\u0435\u043c\u044f. <\/p>\n<h4> \u0411\u0438\u0437\u043d\u0435\u0441-\u043b\u043e\u0433\u0438\u043a\u0430: \u00abservice layer\u00bb \u0441\u043f\u0430\u0441\u0435\u0442<\/h4>\n<p>\u041a\u043e\u0433\u0434\u0430 \u00abdomain\u00bb \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u0442 \u00abrepository\u00bb, \u0430\u00a0\u0442\u043e\u0442 \u043e\u0431\u0440\u0430\u0442\u043d\u043e \u00abdomain\u00bb, \u043f\u043e\u0440\u0430 \u0437\u0430\u0432\u0435\u0441\u0442\u0438 <strong>service layer<\/strong> \u0438 \u0432\u044b\u043d\u0435\u0441\u0442\u0438 \u043e\u0431\u0449\u0438\u0435 \u0442\u0438\u043f\u044b \u0432\u00a0\u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u043c\u043e\u0434\u0443\u043b\u044c <code>common<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0435\u00a0\u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043d\u0438 \u043e\u0442\u00a0\u043e\u0434\u043d\u043e\u0433\u043e \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u0441\u043b\u043e\u044f. \u0422\u0430\u043a \u043f\u043e\u0442\u043e\u043a \u0438\u043c\u043f\u043e\u0440\u0442\u043e\u0432 \u0438\u0434\u0435\u0442 \u0441\u0442\u0440\u043e\u0433\u043e \u0441\u0432\u0435\u0440\u0445\u0443 \u0432\u043d\u0438\u0437.<\/p>\n<h3>\u0422\u0440\u0438 \u043a\u0438\u0442\u0430 \u0430\u043d\u0442\u0438-loop \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u044b<\/h3>\n<h4>\u041a\u0438\u0442 \u2116 1. \u041b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0435 \u0438\u043c\u043f\u043e\u0440\u0442\u044b \u2014 \u0431\u044b\u0441\u0442\u0440\u043e \u0438 \u0433\u0440\u044f\u0437\u043d\u043e<\/h4>\n<p>\u0420\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u043d\u043e\u00a0\u0441\u0442\u0440\u0430\u043d\u043d\u043e \u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0441\u044f \u0432\u00a0\u043a\u043e\u0434\u2011\u0440\u0435\u0432\u044c\u044e. \u041f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code class=\"python\">def send_email(...):     from users import get_user_email     ..<\/code><\/pre>\n<p>\u0423\u0431\u0438\u0440\u0430\u0435\u043c \u0446\u0438\u043a\u043b \u043c\u0433\u043d\u043e\u0432\u0435\u043d\u043d\u043e \u0438 \u044d\u043a\u043e\u043d\u043e\u043c\u0438\u043c \u0432\u0440\u0435\u043c\u044f \u0441\u0442\u0430\u0440\u0442\u0430.<\/p>\n<p>\u041d\u043e\u00a0\u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043b\u0435\u0433\u043a\u043e \u0437\u0430\u0431\u044b\u0442\u044c \u043e\u00a0\u043d\u0438\u0445, \u0441\u043b\u043e\u0436\u043d\u043e \u043c\u043e\u043a\u0430\u0442\u044c \u0432\u00a0\u0442\u0435\u0441\u0442\u0430\u0445. \u0415\u0441\u043b\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0447\u0430\u0441\u0442\u043e, \u0438\u043c\u043f\u043e\u0440\u0442 \u0431\u0443\u0434\u0435\u0442 \u0432\u0430\u043b\u0438\u0442\u044c \u043a\u0435\u0448\u2006\u2011 \u043b\u0435\u0447\u0438\u0442\u0441\u044f \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0435\u043c: <code>if 'users' not in sys.modules: ...<\/code>.<\/p>\n<h4>\u041a\u0438\u0442 \u2116 2. Lazy imports \u043f\u043e PEP 690 <\/h4>\n<p>\u0421\u00a0\u0432\u044b\u0445\u043e\u0434\u043e\u043c 3.13\u00a0\u0432\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0439 \u0444\u043b\u0430\u0433 (\u0438\u043b\u0438 <code>from <strong>future<\/strong> import lazy_imports<\/code>)\u00a0\u2014 \u043c\u043e\u0434\u0443\u043b\u0438 \u0441\u0442\u0430\u043d\u043e\u0432\u044f\u0442\u0441\u044f \u00ab\u0437\u043e\u043c\u0431\u0438\u2011\u043f\u0440\u043e\u043a\u0441\u0430\u043c\u0438\u00bb \u0438 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u043f\u0440\u0438\u00a0\u043f\u0435\u0440\u0432\u043e\u043c \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0438. \u0426\u0438\u043a\u043b \u0440\u0430\u0437\u0440\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0441\u0430\u043c, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e\u00a0\u043a\u043e\u0434, \u0442\u0440\u0435\u0431\u0443\u044e\u0449\u0438\u0439 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c, \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u0432\u0430\u043d <strong>\u043f\u043e\u0441\u043b\u0435<\/strong> \u043f\u043e\u043b\u043d\u043e\u0439 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438.<\/p>\n<p>\u041b\u0435\u043d\u0438\u0432\u044b\u0435 \u0438\u043c\u043f\u043e\u0440\u0442\u044b + Cinder \u0434\u0430\u044e\u0442 \u221240% \u043a\u00a0\u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0434\u043e\u00a0\u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0431\u0430\u0442\u0447\u0430 \u0432\u00a0ML\u2011\u0432\u043e\u0440\u043a\u0444\u043b\u043e\u0443\u00a0\u2014 \u0442\u0430\u043a \u0447\u0442\u043e\u00a0\u043f\u0440\u043e\u0444\u0438\u0442 \u043e\u0449\u0443\u0442\u0438\u043c. <\/p>\n<h4>\u041a\u0438\u0442 \u2116 3. \u0421\u0442\u0440\u043e\u0433\u043e\u0435 \u0440\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u0435 \u0441\u043b\u043e\u0451\u0432<\/h4>\n<ul>\n<li>\n<p><code>api<\/code> \u2192 <code>service<\/code> \u2192 <code>repository<\/code> \u2192 <code>drivers<\/code><\/p>\n<\/li>\n<li>\n<p>\u00ab\u043d\u0438\u0437\u00bb \u043d\u0438\u043a\u043e\u0433\u0434\u0430 \u043d\u0435\u00a0\u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u0442 \u00ab\u0432\u0435\u0440\u0445\u00bb.<\/p>\n<\/li>\n<li>\n<p>\u041e\u0431\u0449\u0438\u0435 enum \u0438 \u0434\u0430\u0442\u0430\u043a\u043b\u0430\u0441\u0441\u044b\u00a0\u2014 \u0432 <code>domain<\/code> \u0438\u043b\u0438 <code>common<\/code>.<\/p>\n<\/li>\n<\/ul>\n<p>\u0421\u0445\u0435\u043c\u0430 \u0431\u0430\u043d\u0430\u043b\u044c\u043d\u0430, \u043d\u043e\u00a0\u0437\u0430\u0442\u044b\u043a\u0430\u0435\u0442 90% \u043a\u0440\u0443\u0433\u043e\u0432\u044b\u0445 \u043e\u0433\u0440\u0435\u0445\u043e\u0432.<\/p>\n<h3>importlib: \u043a\u043e\u0433\u0434\u0430 \u043e\u0447\u0435\u043d\u044c \u043d\u0430\u0434\u043e<\/h3>\n<pre><code class=\"python\">import importlib  def load_plugin(name: str):     return importlib.import_module(f'app.plugins.{name}')<\/code><\/pre>\n<p>\u041f\u043e\u0434\u0433\u0440\u0443\u0436\u0430\u0435\u043c \u043c\u043e\u0434\u0443\u043b\u0438 \u043f\u043e\u00a0\u0441\u0442\u0440\u043e\u043a\u0435, \u0438\u0437\u0431\u0435\u0433\u0430\u044f \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0446\u0438\u043a\u043b\u0430. \u041e\u0442\u043b\u0438\u0447\u043d\u0430\u044f \u0442\u043e\u0447\u043a\u0430 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f \u0434\u043b\u044f\u00a0\u0441\u0438\u0441\u0442\u0435\u043c \u043f\u043b\u0430\u0433\u0438\u043d\u043e\u0432.<\/p>\n<p>\u0418\u043d\u043e\u0433\u0434\u0430 \u043c\u043e\u0434\u0443\u043b\u044c \u0443\u0436\u0435 \u0435\u0441\u0442\u044c \u0432 <code>sys.modules<\/code>, \u043d\u043e\u00a0\u044d\u043a\u0441\u043f\u043e\u0440\u0442 \u043d\u0435\u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u0438\u0437\u2011\u0437\u0430 \u0440\u0430\u043d\u043d\u0435\u0433\u043e \u043f\u0430\u0434\u0435\u043d\u0438\u044f. \u0422\u043e\u0433\u0434\u0430:<\/p>\n<pre><code class=\"python\">module = importlib.reload(sys.modules['users'])<\/code><\/pre>\n<p>\u041d\u0435\u00a0\u0441\u0430\u043c\u044b\u0439 \u0447\u0438\u0441\u0442\u044b\u0439 \u043f\u0430\u0442\u0442\u0435\u0440\u043d, \u043d\u043e\u00a0\u0441\u043f\u0430\u0441\u0430\u0435\u0442.<\/p>\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u0435\u0449\u0451 \u0441\u0438\u0434\u0438\u0442\u0435 \u043d\u0430 3.10\u20133.12, \u043f\u0438\u0448\u0435\u043c \u0441\u0432\u043e\u0439 \u00ab\u043b\u0435\u043d\u0438\u0432\u044b\u0439\u00bb \u0437\u0430\u0433\u0440\u0443\u0437\u0447\u0438\u043a (\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f Python \u043f\u0440\u0438\u0432\u0435\u043b\u0430 \u0448\u0438\u043a\u0430\u0440\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440): <\/p>\n<pre><code class=\"python\">import importlib.util as iu import sys, types  def lazy_import(name):     spec = iu.find_spec(name)     spec.loader = iu.LazyLoader(spec.loader)     module = iu.module_from_spec(spec)     sys.modules[name] = module     spec.loader.exec_module(module)     return module<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c <code>lazy_import(\"numpy\")<\/code> \u043d\u0435\u00a0\u043f\u0440\u043e\u0433\u0440\u0443\u0437\u0438\u0442 200\u00a0\u041c\u0411 C\u2011\u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0439, \u043f\u043e\u043a\u0430 \u0432\u044b \u043d\u0435\u00a0\u0434\u0451\u0440\u043d\u0435\u0442\u0435 <code>numpy.array<\/code>.<\/p>\n<h3>\u041a\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0435 \u043b\u043e\u043c\u0430\u0435\u0442\u0441\u044f<\/h3>\n<h4>Enum-\u044b \u0438 DTO \u2014 \u0432 \u043e\u0434\u043d\u043e\u043c \u043c\u0435\u0441\u0442\u0435<\/h4>\n<pre><code class=\"python\"># common\/types.py from enum import Enum class Role(str, Enum):     ADMIN = 'admin'     USER = 'user'<\/code><\/pre>\n<p><code>users<\/code>, <code>auth<\/code>, <code>payments<\/code> \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u044e\u0442 \u0442\u043e\u043b\u044c\u043a\u043e <code>Role<\/code>, \u043d\u043e\u00a0\u043d\u0435\u00a0\u0434\u0440\u0443\u0433 \u0434\u0440\u0443\u0433\u0430.<\/p>\n<h4>\u0424\u0430\u0431\u0440\u0438\u043a\u0438 \u0432\u043c\u0435\u0441\u0442\u043e \u043f\u0440\u044f\u043c\u044b\u0445 \u0441\u0441\u044b\u043b\u043e\u043a<\/h4>\n<pre><code class=\"r\"># services\/email_service.py def get_email_sender():     from adapters.smtp import SmtpSender     return SmtpSender(...)<\/code><\/pre>\n<p>\u0422\u0435\u0441\u0442 \u043b\u0435\u0433\u043a\u043e \u043f\u043e\u0434\u043c\u0435\u043d\u0438\u0442\u044c \u0447\u0435\u0440\u0435\u0437 monkey\u2011patch:<\/p>\n<pre><code class=\"python\">monkeypatch.setattr(email_service, 'get_email_sender', FakeSender)<\/code><\/pre>\n<h4>\u041f\u0430\u0442\u0442\u0435\u0440\u043d \u00ab\u0432\u0435\u0440\u0445\u043d\u0438\u0439 \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u2014 \u0442\u043e\u043b\u044c\u043a\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b\u00bb<\/h4>\n<pre><code># repos\/__init__.py from .base import AbstractRepo<\/code><\/pre>\n<p><code>service.py<\/code> \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u0442 <code>AbstractRepo<\/code>, \u0430\u00a0\u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f <code>PgRepo<\/code> \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 DI\u2011\u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, repo \u00ab\u0437\u043d\u0430\u0435\u0442\u00bb \u043e\u00a0service? \u041d\u0435\u0442, \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430\u043e\u0431\u043e\u0440\u043e\u0442.<\/p>\n<h3>\u041e\u0441\u0442\u0440\u044b\u0435 \u0443\u0433\u043e\u043b\u043a\u0438<\/h3>\n<ol>\n<li>\n<p><strong>\u00ab\u041b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0435 \u0438\u043c\u043f\u043e\u0440\u0442\u044b\u00a0\u2014 \u044d\u0442\u043e \u043d\u0435\u043a\u0440\u0430\u0441\u0438\u0432\u043e\u00bb<\/strong>. \u0421\u043e\u0433\u043b\u0430\u0441\u0435\u043d, \u043d\u043e\u00a0\u043a\u043e\u0433\u0434\u0430 \u0433\u043e\u0440\u0438\u0442, \u0441\u0442\u043e\u0438\u0442 \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u0440\u0430\u0431\u043e\u0447\u0435\u0435 \u0438 \u0443\u0440\u043e\u0434\u043b\u0438\u0432\u043e\u0435\u00bb \u0432\u043c\u0435\u0441\u0442\u043e \u00ab\u043a\u0440\u0430\u0441\u0438\u0432\u043e\u0435, \u043d\u043e\u00a0\u043b\u0435\u0436\u0438\u0442\u00bb.<\/p>\n<\/li>\n<li>\n<p><strong>Lazy imports \u0441\u043a\u0440\u044b\u0432\u0430\u044e\u0442 \u043e\u0448\u0438\u0431\u043a\u0438<\/strong>: \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0432\u0441\u043f\u043b\u044b\u0432\u0430\u044e\u0442 \u043d\u0435\u00a0\u043d\u0430\u00a0\u0441\u0442\u0430\u0440\u0442\u0435, \u0430\u00a0\u0432\u00a0\u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442. \u041b\u043e\u0433\u0438\u0440\u0443\u0439\u0442\u0435 <code>importlib.invalidate_caches()<\/code> \u043d\u0430\u00a0CI \u0438 \u0433\u043e\u043d\u044f\u0439\u0442\u0435 <code>pytest -Werror<\/code>.<\/p>\n<\/li>\n<li>\n<p><strong>\u0421\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0430\u043d\u0430\u043b\u0438\u0437<\/strong> (mypy, pylint) \u043c\u043e\u0436\u0435\u0442 \u043d\u0435\u00a0\u0432\u0438\u0434\u0435\u0442\u044c \u0434\u0438\u043d\u0430\u043c\u0438\u043a\u0443. \u0420\u0435\u0448\u0435\u043d\u0438\u0435\u00a0\u2014 <code>typing.TYPE_CHECKING<\/code> \u0438 \u043f\u0441\u0435\u0432\u0434\u043e\u2011\u0438\u043c\u043f\u043e\u0440\u0442:<\/p>\n<pre><code>from typing import TYPE_CHECKING if TYPE_CHECKING:     from service import ImportantClass<\/code><\/pre>\n<\/li>\n<li>\n<p><strong>\u0420\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433 \u0441\u0442\u043e \u0441\u0442\u0440\u043e\u043a vs. \u0440\u0443\u0447\u043a\u0430 <\/strong><code><strong>reload<\/strong><\/code>. \u042f \u0437\u0430\u00a0\u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433: \u0434\u043e\u043b\u0433\u043e\u0441\u0440\u043e\u0447\u043d\u043e \u0434\u0435\u0448\u0435\u0432\u043b\u0435.<\/p>\n<\/li>\n<\/ol>\n<hr\/>\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u0434\u043e\u0447\u0438\u0442\u0430\u043b\u0438 \u0434\u043e \u044d\u0442\u043e\u0433\u043e \u043c\u0435\u0441\u0442\u0430, \u0441\u043a\u043e\u0440\u0435\u0435 \u0432\u0441\u0435\u0433\u043e, \u0443\u0436\u0435 \u0441\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u043b\u0438\u0441\u044c \u0441 \u043a\u0440\u0443\u0433\u043e\u0432\u044b\u043c\u0438 \u0438\u043c\u043f\u043e\u0440\u0442\u0430\u043c\u0438 \u0438\u043b\u0438 \u043a\u0430\u043a \u043c\u0438\u043d\u0438\u043c\u0443\u043c \u0441 \u0431\u043e\u043b\u044c\u044e \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u043d\u044b\u0445 \u043a\u043e\u0441\u0442\u044b\u043b\u0435\u0439. \u0410 \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u044c\u0442\u0435: \u0432\u0430\u0448 \u043a\u043e\u0434 \u043d\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0435 \u043b\u043e\u043c\u0430\u0435\u0442\u0441\u044f \u2014 \u043e\u043d \u0443\u0441\u0442\u043e\u0439\u0447\u0438\u0432, \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u0443\u0435\u043c \u0438 \u0433\u043e\u0442\u043e\u0432 \u043a \u0440\u043e\u0441\u0442\u0443 \u043a\u043e\u043c\u0430\u043d\u0434\u044b.<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u043a \u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u0438\u0439\u0442\u0438 \u2014 \u0441\u0442\u043e\u0438\u0442 \u043d\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u0433\u0443\u0433\u043b\u0438\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0438, \u0430 \u043a\u043e\u043f\u0430\u0442\u044c \u0433\u043b\u0443\u0431\u0436\u0435. \u041c\u044b \u0432 OTUS \u043a\u0430\u043a \u0440\u0430\u0437 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0441\u0434\u0435\u043b\u0430\u043b\u0438 \u0434\u0432\u0430 \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u0445 \u0443\u0440\u043e\u043a\u0430. \u0411\u0435\u0437 \u00ab\u0432\u043e\u0434\u044b\u00bb, \u0441 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u043e\u0439 \u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0439:<\/p>\n<ul>\n<li>\n<p><a href=\"https:\/\/otus.pw\/92WI\/\" rel=\"noopener noreferrer nofollow\"><strong>\u041e\u0441\u043d\u043e\u0432\u044b \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0439 \u0442\u0438\u043f\u043e\u0432 \u0432 Python<\/strong><\/a> \u2014 <em>26 \u0438\u044e\u043d\u044f \u0432 20:00<\/em><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/otus.pw\/t0Dm\/\" rel=\"noopener noreferrer nofollow\"><strong>\u0428\u0438\u043a, \u0431\u043b\u0435\u0441\u043a, \u0447\u0438\u0441\u0442\u043e\u0442\u0430: clean architecture \u0432 Python<\/strong><\/a> \u2014 <em>1 \u0438\u044e\u043b\u044f \u0432 20:00<\/em><\/p>\n<\/li>\n<\/ul>\n<p>\u0410\u00a0\u0435\u0441\u043b\u0438 \u043f\u043e\u0441\u043b\u0435 \u0443\u0440\u043e\u043a\u043e\u0432 \u0432\u044b \u0437\u0430\u0445\u043e\u0442\u0438\u0442\u0435 \u0434\u0432\u0438\u0433\u0430\u0442\u044c\u0441\u044f \u0434\u0430\u043b\u044c\u0448\u0435\u00a0\u2014 \u0437\u0430\u0433\u043b\u044f\u043d\u0438\u0442\u0435 \u043d\u0430\u00a0\u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443 \u043a\u0443\u0440\u0441\u0430 <a href=\"https:\/\/otus.pw\/sQXuF\/\" rel=\"noopener noreferrer nofollow\">\u00ab\u0421\u043f\u0435\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f Python Developer\u00bb<\/a>. \u041c\u044b \u043f\u043e\u0441\u0442\u0430\u0440\u0430\u043b\u0438\u0441\u044c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u043f\u0440\u0438\u043a\u043b\u0430\u0434\u043d\u043e\u0439 \u0438 \u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u043d\u0430\u00a0\u0440\u0435\u0430\u043b\u044c\u043d\u0443\u044e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0443.<\/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\/919676\/\"> https:\/\/habr.com\/ru\/articles\/919676\/<\/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-464521","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/464521","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=464521"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/464521\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=464521"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=464521"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=464521"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}