跳转到主要内容

flake8的一个扩展,禁止某些模块中的某些导入语句。

项目描述

flake8-obey-import-goat

flake8的一个扩展,禁止某些模块中的某些导入语句。

重要:该项目使用DDD开发,因此部分文档可能不存在。请保持关注 :)

安装

pip install flake8-obey-import-goat

示例

# foo.py
from datetime import datetime
from typing import Optional

def foo():
    pass


# users/bar.py
from foo import foo


# users/domain.py
def foo():
    pass


# users/implementation.py
from users.domain import foo


# orders/implementation.py
from users.domain import foo
# setup.cfg
[flake8]
forbidden-imports =
    *: datetime.datetime, stdlib modules should be imported as a module
    *: typing.Optional, we use T | None instead of Optional[T]
    users.*: foo.*, users module should not use foo module
    *.implementation.*: *.domain.*, implementation layer should not use domain layer

用法

$ flake8 test.py
foo.py:1:1: OIG001 datetime.datetime is forbidden, since stdlib modules should be imported as a module.
foo.py:2:1: OIG001 typing.Optional is forbidden, since we use T | None instead of Optional[T].
users/bar.py:1:1: OIG001 foo.foo import is forbidden is forbidden, since users module should not use foo module.
users/implementation.py:1:1: OIG001 *.domain.* import is forbidden is forbidden, since implementation layer should not use domain layer.
orders/implementation.py:1:1: OIG001 *.domain.* import is forbidden is forbidden, since implementation layer should not use domain layer.

在Python 3.9+和flake8 4.0+上测试过。

错误代码

错误代码 描述
OIG001 importable被禁止,因为

项目详情


下载文件

下载适合您平台的文件。如果您不确定选择哪个,请了解有关 安装软件包 的更多信息。

源分布

flake8_obey_import_goat-0.1.1.tar.gz (4.3 kB 查看散列)

上传时间:

由以下支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误记录 StatusPage StatusPage 状态页面