flake8-import-restrictions


Nameflake8-import-restrictions JSON
Version 2.1 PyPI version JSON
download
home_pagehttps://github.com/atollk/flake8-import-restrictions
SummaryA flake8 plugin used to disallow certain forms of imports.
upload_time2024-08-29 11:15:10
maintainerNone
docs_urlNone
authorAndreas Tollkötter
requires_python>=3.8
licenseMIT
keywords flake8 import
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # flake8-import-restrictions
[![Build Status](https://github.com/atollk/flake8-import-restrictions/workflows/tox/badge.svg)](https://github.com/atollk/flake8-import-restrictions/actions)
[![Build Status](https://github.com/atollk/flake8-import-restrictions/workflows/pylint/badge.svg)](https://github.com/atollk/flake8-import-restrictions/actions)
[![Build Status](https://github.com/atollk/flake8-import-restrictions/workflows/black/badge.svg)](https://github.com/atollk/flake8-import-restrictions/actions)
[![Build Status](https://github.com/atollk/flake8-import-restrictions/workflows/flake8/badge.svg)](https://github.com/atollk/flake8-import-restrictions/actions)

A flake8 plugin used to disallow certain forms of imports.

This plugin talks about the `import` syntax (`import X.Y.Z [as foo]`)
and the `from` syntax (`from X.Y import Z [as foo]`). It talks about
`import` segments (`import X`), `from` segments (`from Y`), and `as`
segments (`as Z`).

## Options
For every error `IMR2xx` listed below, there are options `--imr2xx_include` and `--imr2xx_exclude` 
which are passed a comma separated list of UNIX wildcard patterns each. The error
will then only be reported on imports of modules that match a include pattern but no exclude 
pattern.

By default, IMR200, IMR201, IMR202, IMR221, IMR223, IMR241, and IMR243 include all (`*`) modules. Only IMR241 excludes the
`typing` module from checks, the other errors have no excludes by default.

## General Import Errors

### IMR200
Imports should only happen on module level, not locally.

```python
# Bad
def f():
    import os.path
    return os.path.join("a", "b")

# Good
import os.path
def f():
    return os.path.join("a", "b")
```

### IMR201
Alias identifiers defined from `as` segments should be at
least two characters long.

```python
# Bad
import os.path as p

# Good
import os.path as path
```

### IMR202
Alias identifiers should not have the same name as the imported object.

```python
# Bad
import sys as sys

# Good
import sys
```

## `import` Syntax Errors

### IMR220
When using the `import` syntax, if the imported module is a submodule,
i.e. not a top level module, an `as` segment should be present.

```python
# Bad
import os.path

# Good
import sys
import os.path as path
```

### IMR221
When using the `import` syntax, each import statement should
only import one module.

```python
# Bad
import sys, os

# Good
import sys
import os
```

### IMR222
The `import` syntax should not be used.


### IMR223
When using the `import` syntax, do not duplicate module names in the `as`
segment.

```python
# Bad
import os.path as path

# Good
from os import path
import os.path as ospath
```


## `from` Syntax Errors

### IMR240
When using the `from` syntax, the `import` segment only contains one
import.

```python
# Bad
from os import path, environ

# Good
from os import path
from os import environ
```

### IMR241
When using the `from` syntax, only submodules are imported, not
module elements.

```python
# Bad
from os.path import join

# Good
from os import path
```

### IMR242
When using the `from` syntax, only module elements are imported,
not submodules.

```python
# Bad
from os import path

# Good
from os.path import join
```

### IMR243
When using the `from` syntax, `import *` should not be used.

```python
# Bad
from os.path import *

# Good
from os.path import join
```

### IMR244
Relative imports should not be used.

```python
# Bad
from . import foo

# Good
from flake8_import_restrictions import foo
```

### IMR245
The `from` syntax should not be used.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/atollk/flake8-import-restrictions",
    "name": "flake8-import-restrictions",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "flake8, import",
    "author": "Andreas Tollk\u00f6tter",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/cd/25/edfb89dded3644c3371c706b9f7165a9f05deb1137960fdbf93cc96760e7/flake8_import_restrictions-2.1.tar.gz",
    "platform": null,
    "description": "# flake8-import-restrictions\n[![Build Status](https://github.com/atollk/flake8-import-restrictions/workflows/tox/badge.svg)](https://github.com/atollk/flake8-import-restrictions/actions)\n[![Build Status](https://github.com/atollk/flake8-import-restrictions/workflows/pylint/badge.svg)](https://github.com/atollk/flake8-import-restrictions/actions)\n[![Build Status](https://github.com/atollk/flake8-import-restrictions/workflows/black/badge.svg)](https://github.com/atollk/flake8-import-restrictions/actions)\n[![Build Status](https://github.com/atollk/flake8-import-restrictions/workflows/flake8/badge.svg)](https://github.com/atollk/flake8-import-restrictions/actions)\n\nA flake8 plugin used to disallow certain forms of imports.\n\nThis plugin talks about the `import` syntax (`import X.Y.Z [as foo]`)\nand the `from` syntax (`from X.Y import Z [as foo]`). It talks about\n`import` segments (`import X`), `from` segments (`from Y`), and `as`\nsegments (`as Z`).\n\n## Options\nFor every error `IMR2xx` listed below, there are options `--imr2xx_include` and `--imr2xx_exclude` \nwhich are passed a comma separated list of UNIX wildcard patterns each. The error\nwill then only be reported on imports of modules that match a include pattern but no exclude \npattern.\n\nBy default, IMR200, IMR201, IMR202, IMR221, IMR223, IMR241, and IMR243 include all (`*`) modules. Only IMR241 excludes the\n`typing` module from checks, the other errors have no excludes by default.\n\n## General Import Errors\n\n### IMR200\nImports should only happen on module level, not locally.\n\n```python\n# Bad\ndef f():\n    import os.path\n    return os.path.join(\"a\", \"b\")\n\n# Good\nimport os.path\ndef f():\n    return os.path.join(\"a\", \"b\")\n```\n\n### IMR201\nAlias identifiers defined from `as` segments should be at\nleast two characters long.\n\n```python\n# Bad\nimport os.path as p\n\n# Good\nimport os.path as path\n```\n\n### IMR202\nAlias identifiers should not have the same name as the imported object.\n\n```python\n# Bad\nimport sys as sys\n\n# Good\nimport sys\n```\n\n## `import` Syntax Errors\n\n### IMR220\nWhen using the `import` syntax, if the imported module is a submodule,\ni.e. not a top level module, an `as` segment should be present.\n\n```python\n# Bad\nimport os.path\n\n# Good\nimport sys\nimport os.path as path\n```\n\n### IMR221\nWhen using the `import` syntax, each import statement should\nonly import one module.\n\n```python\n# Bad\nimport sys, os\n\n# Good\nimport sys\nimport os\n```\n\n### IMR222\nThe `import` syntax should not be used.\n\n\n### IMR223\nWhen using the `import` syntax, do not duplicate module names in the `as`\nsegment.\n\n```python\n# Bad\nimport os.path as path\n\n# Good\nfrom os import path\nimport os.path as ospath\n```\n\n\n## `from` Syntax Errors\n\n### IMR240\nWhen using the `from` syntax, the `import` segment only contains one\nimport.\n\n```python\n# Bad\nfrom os import path, environ\n\n# Good\nfrom os import path\nfrom os import environ\n```\n\n### IMR241\nWhen using the `from` syntax, only submodules are imported, not\nmodule elements.\n\n```python\n# Bad\nfrom os.path import join\n\n# Good\nfrom os import path\n```\n\n### IMR242\nWhen using the `from` syntax, only module elements are imported,\nnot submodules.\n\n```python\n# Bad\nfrom os import path\n\n# Good\nfrom os.path import join\n```\n\n### IMR243\nWhen using the `from` syntax, `import *` should not be used.\n\n```python\n# Bad\nfrom os.path import *\n\n# Good\nfrom os.path import join\n```\n\n### IMR244\nRelative imports should not be used.\n\n```python\n# Bad\nfrom . import foo\n\n# Good\nfrom flake8_import_restrictions import foo\n```\n\n### IMR245\nThe `from` syntax should not be used.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A flake8 plugin used to disallow certain forms of imports.",
    "version": "2.1",
    "project_urls": {
        "Homepage": "https://github.com/atollk/flake8-import-restrictions"
    },
    "split_keywords": [
        "flake8",
        " import"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f6619155263732f085bf757d6687a06d31499d1b13a54a3dd903ad41573cf5c2",
                "md5": "a3d84af810904fcb42be5ced39c09fa0",
                "sha256": "77522e76b82a6ccb25820b1e195825a695094ceded23a18c1b5ce026c23e1071"
            },
            "downloads": -1,
            "filename": "flake8_import_restrictions-2.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "a3d84af810904fcb42be5ced39c09fa0",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 7515,
            "upload_time": "2024-08-29T11:15:09",
            "upload_time_iso_8601": "2024-08-29T11:15:09.534434Z",
            "url": "https://files.pythonhosted.org/packages/f6/61/9155263732f085bf757d6687a06d31499d1b13a54a3dd903ad41573cf5c2/flake8_import_restrictions-2.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "cd25edfb89dded3644c3371c706b9f7165a9f05deb1137960fdbf93cc96760e7",
                "md5": "788eb087c64250c046b163c666482ddf",
                "sha256": "f27cb026e45ca60adfe7281f7145a250dbcc289b7cbc877a8cd295ee935bd56c"
            },
            "downloads": -1,
            "filename": "flake8_import_restrictions-2.1.tar.gz",
            "has_sig": false,
            "md5_digest": "788eb087c64250c046b163c666482ddf",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 8651,
            "upload_time": "2024-08-29T11:15:10",
            "upload_time_iso_8601": "2024-08-29T11:15:10.935328Z",
            "url": "https://files.pythonhosted.org/packages/cd/25/edfb89dded3644c3371c706b9f7165a9f05deb1137960fdbf93cc96760e7/flake8_import_restrictions-2.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-29 11:15:10",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "atollk",
    "github_project": "flake8-import-restrictions",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "flake8-import-restrictions"
}
        
Elapsed time: 0.32392s