flake8_custom_import_rules 1.1.6
A Flake8 plugin that enforces custom import rules, allowing users to define and maintain clean and consistent import organization across their Python projects.
License: MIT
Requires Python: <4,>=3.9
Keywords: code_quality, code_linting, import_rules, flake8, quality_assurance

==========================
flake8-custom-import-rules
==========================
.. image:: https://images.squarespace-cdn.com/content/v1/5739206dc6fc0814566cf91d/1692854973337-STZOMBOTWFPEVZVQ4GRI/dependency-wheel.png?format=1000w
   :target: https://rodrigo-gonzalez.com/projects#/flake8-custom-import-rules/
   :alt: Project Dependency Wheel

.. image:: https://img.shields.io/pypi/v/flake8-custom-import-rules.svg?style=flat-square
    :target: https://pypi.org/project/flake8-custom-import-rules/
    :alt: PyPI Package latest release

.. image:: https://img.shields.io/pypi/pyversions/flake8-custom-import-rules.svg?style=flat-square
    :target: https://pypi.org/project/flake8-custom-import-rules/
    :alt: Supported versions

.. image:: https://img.shields.io/badge/code%20style-black-000000.svg
    :target: https://github.com/psf/black

.. image:: https://codecov.io/gh/RodrigoGonzalez/flake8-custom-import-rules/graph/badge.svg?token=WIQPI6YRBL
    :target: https://codecov.io/gh/RodrigoGonzalez/flake8-custom-import-rules






A ``flake8`` plugin that enforces custom import rules, allowing
users to define and maintain clean and consistent import
organization across their Python projects.

This plugin takes advantage of ``flake8`` linting
capabilities and provides set of flags that enable you to
specify import restrictions, standalone packages and modules,
and additional custom and project-level import rules.
These flags can be used in conjunction
with each other to provide granular control over your import rules.
The use of these flags is highly dependent on the specific
needs and coding standards of your project. They provide
a means to enforce certain styles or practices, but may
not be necessary or beneficial in all cases. It's important
to consider the trade-offs and potential impacts before
deciding to use these restrictions.

There are two types of import rules that can be enforced by
this plugin:

-   Custom Import Rules (CIR) allow you to define and enforce
    import rules for specific package and modules within your
    project.
-   Project Import Rules (PIR) allow you to define and enforce
    import rules at a project level.


Detailed Documentation: https://rodrigogonzalez.github.io/flake8-custom-import-rules/


.. contents:: **Sections**
   :depth: 2


**Introduction**
----------------

This ``flake8`` plugin significantly enhances the organization
and consistency of imports in Python projects. By enabling
developers to set custom restrictions, define standalone
packages, and establish import rules, the plugin aids in
mitigating unwanted dependencies and maintaining clear separations
between packages. Specifically, it facilitates the management of
lightweight packages by limiting their imports to the Python
standard library or third-party libraries, thus preventing
unnecessary dependencies.

Beyond enhancing readability and maintainability, the plugin
promotes a modular architecture that is easier to comprehend,
test, and debug. Consequently, developers can smoothly adhere
to best practices, maintaining their projects in a clean,
organized, and collaborative-friendly state.

NOTE: While certain options might be considered niche and
are unlikely to be employed in everyday scenarios, their
inclusion is a deliberate design choice aimed at empowering
users with the utmost control and flexibility.


**Installation**
----------------

Install from ``pip`` with:

.. code-block:: sh

     pip install flake8-custom-import-rules


**Development**
---------------

Additional details on how to develop and contribute to this
plugin coming soon.


**Plugin Options: Required Flags & Options**
--------------------------------------------
The following flag is required to enable most of the
plugin functionality:

- base-packages


Base Packages Option
~~~~~~~~~~~~~~~~~~~~
The `--base-packages` flag serves as a foundational configuration
option within the tool, allowing users to explicitly define
the primary packages that constitute their project. These
identified packages are categorized as first-party,
signifying the core elements that are actively being developed
within the scope of the project itself.

By specifying the base packages, users create a clear
delineation between their main project components and external
dependencies. This distinction assists in various operations,
such as linting, dependency analysis, and code organization.

For instance, if a user is developing a library named
`my_library`, they would include `my_library` as a base
package by configuring this flag. This inclusion ensures
that the tool recognizes `my_library` a the reference
package for imposing many of the rules the user is
likely to define or enable, aligning its behavior with the
user's development practices. As seen below:

.. code-block:: ini

    [flake8]
    base-packages = my_library,my_other_library

It's important to note that if the base-packages flag is
not configured, the majority of functionality within the
tool will be limited or disabled. This flag is instrumental
in tailoring the plugin's behavior to the specific
structure and needs of the project.

That said, the project import rules (PIR) are not dependent
on the base-packages flag, and can be used independently,
therefore the base-packages flag is not set to as required
within the ``flake8`` framework.


**Plugin Options: Custom Import Rules (CIR)**
---------------------------------------------

Custom Import Rules (CIR) allow you to define and enforce
import rules for modules and packages within your project.

The following flags are available to restrict specific types
of imports:


=======================  =====================================================
 Custom Import Rules        Description
=======================  =====================================================
restricted-packages         This flag restricts the import of specified
                            packages into all other packages within your
                            project. It can be used to
                            prevent the use of packages known to cause
                            problems or that are undesired for specific
                            reasons. For instance, it can enforce a clear
                            separation between high-level and low-level
                            packages (e.g., the `app` package should not
                            be imported by `common`, `utils`, `core`, etc.).

std-lib-only                This flag ensures that only standard
                            library modules can be imported within the
                            specified package or module. It is useful in
                            scenarios where the target is intended to rely
                            solely on the standard library, without any
                            third-party or project dependencies. For
                            example, low-level packages that are used
                            across the rest of the project can be
                            restricted.

project-only                This flag enforces that only project
                            packages can be imported in the specified
                            modules and packages. This can be used
                            in a package where third-party dependencies
                            are intended to be minimized, and most of
                            the functionality is implemented within the
                            project itself. These are defined by the
                            base-packages flag.

base-package-only           This flag enforces that only the root
                            package of the project can be imported
                            into the specified packages or modules.
                            It ensures that only the root package is
                            solely relied on. Useful in a project where
                            a clear hierarchy and dependency flow is
                            required, and all functionality must be
                            accessed through the root package.

first-party-only            This flag enforces that only first-party
                            modules (i.e., developed as part of the
                            project) can be imported, including all
                            imports in base packages except for its
                            own root package. Useful in security-
                            sensitive environments, or to minimize
                            external dependencies, giving more control
                            over the codebase.

third-party-only            This flag enforces that only third-party
                            modules can be imported, restricting the
                            use of standard library or project-specific
                            modules. For example, in a plugin system
                            designed to extend functionality using
                            third-party libraries, this flag would
                            ensure that only those external libraries
                            are imported, excluding standard or
                            project-level modules. Unlike the
                            standalone-modules rule, third-party-only
                            does not allow imports from within the
                            specific module or package itself.

standalone-modules          This flag allows you to define a list of
                            packages that cannot import from any other
                            packages within your project, except for
                            modules and packages within the parent
                            package. This ensures that certain packages
                            remain standalone and do not introduce
                            unwanted dependencies.
                            For instance, you might have
                            a 'standalone_package' that performs a
                            specific task independently. To ensure it
                            remains decoupled from the rest of the
                            application, you can make this package
                            standalone. It promotes modular design,
                            aiding in maintainability and scalability.
                            (e.g., within your base package typically
                            have names like `common`, `utils`,
                            `helpers`, etc.)

custom-restrictions         This flag enables granular control over
                            the importing of specific packages or
                            modules within your project. It allows you
                            to specify a package or module, followed by
                            a colon, and then list the restricted imports,
                            separated by additional colons.
                            These restricted imports can include other
                            first-party packages, standard library
                            packages, or third-party imports. Particularly
                            useful in large projects, this flexibility
                            helps in managing complex dependencies.
                            Consider a scenario where `package_a` handles
                            raw data cleaning, and `package_b` processes
                            sensitive data. To prevent accidental leakage
                            of raw data into `package_b`, you could
                            restrict `package_a` from importing `package_b`
                            or its subpackages.

=======================  =====================================================


Each of these flags can be set according to the specific needs
and structure of the project, allowing for a high level of
customization of the import rules.

Restricted Packages Option
~~~~~~~~~~~~~~~~~~~~~~~~~~

The `--restricted-packages` flag allows you to specify high-level
packages that should not be imported into any other packages within
your project. This maintains the integrity of high-level packages,
ensuring that they are not tightly coupled with other parts of the
codebase.

For example, if you have a high-level package like 'app' responsible
for core functionality, you may want to prevent it from being
imported into lower-level packages such as 'common', 'utils', 'core',
etc. This can help avoid circular dependencies and preserve a clean
architectural hierarchy.

.. code-block:: ini

    [flake8]
    restricted_packages = app


Standard Library Only Imports Option
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The `--std-lib-only` flag enables you to designate specific packages
within your project that are restricted to importing only from the
Python standard library. This maintains a lightweight footprint for
those packages, ensuring they remain easily portable and free from
third-party dependencies.

For example, you might be developing a 'lightweight_package' meant
to be used across various environments without the need for additional
dependencies. By restricting this package to import only from the
Python standard library, you can ensure its compatibility and ease of
use.

.. code-block:: ini

    [flake8]
    std_lib_only = lightweight_package


Project Only Imports Option
~~~~~~~~~~~~~~~~~~~~~~~~~~~

The `--project-only` flag restricts specified modules and packages
within your project to import solely from other packages developed
as part of the project and the standard library. This ensures that
the internal functionality is prioritized, and third-party
dependencies are minimized.

Consider a scenario where you want to maintain the integrity and
independence of your project's core functionality. By using the
`project-only` option, you can ensure that specific modules or
packages rely exclusively on the internally developed code, reducing
the risk of external dependencies and promoting a cohesive codebase.

For example, if you have a package 'package_a' and you want to restrict
it to only import from the local package and the project's top-level
package, you can specify:

.. code-block:: ini

    [flake8]
    project_only = package_a

In this configuration, 'package_a' is limited to importing only from
other packages defined within the project, fostering a controlled
and self-contained development environment.


Base Package Only Imports Option
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The `--base-package-only` flag is a powerful tool for
enforcing a hierarchical structure within your project. By
specifying packages or modules with this flag, you ensure
that they can only import from the project's root package.
This centralizes the dependency flow and promotes a
well-structured project design.

Consider a complex project with multiple interdependent
packages. You might want to ensure that certain packages
rely solely on the root package to minimize potential
conflicts and promote maintainability. The
`base-package-only` option allows you to create this clear
and organized dependency structure.

For example, suppose you have a package named `package_h`
that you want to restrict to only import from the top-level
package of your project. You can specify this as follows:

.. code-block:: ini

    [flake8]
    base_package_only = my_base_package.package_h

In this configuration, 'package_h' can only import from
`my_base_package`. Any attempt to import from other
packages will be flagged by the linter. This ensures that
`my_base_package` remains the central point of interaction,
providing better control and clarity in the project's
architecture.

Now, let's consider another package, `my_second_package`.
Suppose you want to ensure that `my_second_package` does
not import any other packages specified in base-packages.
This might be useful if 'my_second_package' is designed to
be independent or if it contains functionality that should
not be influenced by other parts of the project. You can
specify this restriction as follows:

.. code-block:: ini

    [flake8]
    base_package_only = my_base_package.package_h, my_second_package

With this configuration, `my_second_package` is restricted
from importing any other packages specified in
base-packages. This ensures the independence of
`my_second_package`, allowing it to function without being
affected by changes in other parts of the project.


First-Party Only Imports Option
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The `--first-party-only` flag ensures that only first-party modules,
i.e., those developed within the project, can be imported. This
restriction includes all imports defined within the base packages,
excluding the imports from its own root package.

This control over imports can be highly beneficial in security-
sensitive environments or in projects aiming to minimize external
dependencies. By limiting the imports to first-party modules, you
gain more control over the codebase and reduce potential risks
associated with third-party dependencies.

Consider a scenario where your project requires strict compliance
with certain regulations or standards. By enforcing a first-party
only import policy, you can ensure that all code is vetted and
maintained within your organization, reducing potential legal or
security concerns.

To implement this restriction, you can specify:

.. code-block:: ini

    [flake8]
    first_party_only = my_project.my_package

In this example, 'my_package' within 'my_project' will only be
allowed to import modules developed as part of the project. Any
attempt to import from outside the project will be flagged by
the linter, helping to maintain the integrity and security of
the codebase.


Third-Party Only Imports Option
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The `--third-party-only` flag is designed to enforce the use of
only third-party modules in the specified packages or modules. This
restriction prohibits the import of both standard library modules
and project-specific modules, ensuring that only external libraries
are utilized.

Such a restriction can be particularly useful in scenarios where
a system is designed to extend its functionality exclusively through
third-party libraries. For instance, in a plugin system that relies
on external extensions, this flag guarantees that only those third-
party libraries are imported, excluding any standard or project-level
modules.

Unlike the `standalone-modules` rule, the `third-party-only` rule
prevents even the importation of modules from within the specified
package or module itself, further narrowing the scope of allowed
imports.

To apply this restriction, you can specify:

.. code-block:: ini

    [flake8]
    third_party_only = my_plugin_system.my_plugin

In this example, 'my_plugin' within 'my_plugin_system' will be
restricted to importing only third-party modules. Any attempt to
import from the standard library or from other modules within the
project will be flagged by the linter. This ensures a strict
adherence to the design principles of relying solely on third-party
extensions, maintaining the integrity of the plugin system.


Standalone Modules Option
~~~~~~~~~~~~~~~~~~~~~~~~~

The `--standalone-modules` flag is designed to allow specific
packages or modules to import only from the standard library,
the base package of the project, and third-party libraries,
excluding any other first-party or project-level imports.
This ensures that the specified standalone packages or modules
operate independently from other parts of the project, yet they
still have access to essential third-party libraries, the base
package, and standard libraries.

This option aids in maintainability and scalability, especially
in complex projects where clear boundaries and modular design
are essential. Standalone modules or packages can be used to
encapsulate specific functionalities that don't require
integration with the rest of the first-party code.

Here's an example of how you can configure this rule:

.. code-block:: ini

    [flake8]
    standalone_modules = my_base_package.standalone_module

In this example, 'standalone_module' within 'my_base_package'
is configured to import only from the standard library, the
base package itself, and third-party libraries. Any attempt to
import from other first-party packages or modules within the
project will be flagged by the linter.

It's worth noting the difference between the `standalone-modules`
rule and the `third-party-only` rule. While both restrict
project-specific imports, `standalone-modules` allows imports
from within the standalone package or module itself, whereas
`third-party-only` does not, further narrowing the scope of
allowed imports.

By employing the `standalone-modules` option, developers can
ensure that certain parts of the application remain decoupled
and self-contained, promoting a clean and organized code
structure that can be more easily managed and expanded.


Custom Restrictions Option
~~~~~~~~~~~~~~~~~~~~~~~~~~

The `--custom-restrictions` flag provides a powerful tool for
managing and limiting specific import capabilities within your
project. It enables you to precisely control the import behavior
of individual packages or modules, ensuring that certain imports
are restricted as per the project's requirements.

This control is achieved by specifying a package or module,
followed by a colon, and then listing the restricted imports,
separated by additional colons. These restricted imports can
range from other first-party packages within the project to
standard library packages, or even third-party imports.

Such granularity is particularly valuable in large or complex
projects where managing dependencies and maintaining a clear
structure can be challenging. For example, you may have
`package_a` responsible for raw data cleaning and `package_b`
for processing sensitive data. To avoid accidental leakage of
raw data into `package_b`, you could apply restrictions to
prevent `package_a` from importing `package_b` or any of its
subpackages.

The configuration might look like this:

.. code-block:: ini

    [flake8]
    custom-restrictions =
        # Restrict `package_a` from importing `package_b` and `os`
        my_base_package.package_a:my_base_package.package_b:os
        # Restrict `module_x` from importing `module_y` and `pandas`
        my_base_package.module_x:my_base_package.module_y:pandas

In the example above, specific restrictions are applied to
`package_a` and `module_x`, preventing them from importing
certain other packages or modules within the project, or even
from the standard library or third-party libraries. Again,
this is to provide a granular level of control over the
import behavior of individual packages or modules, restricting
imports from `pandas` or even `os` is not very likely within
your own project, but there may reasons make these restrictions.
This ensures that the intended separation and containment of
functionality are preserved, enhancing the maintainability
and security of the codebase.



Custom Import Rules: Import Rules and Import Types Table
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Remember to carefully assess your project's needs and structure
when applying these import rules, as they can significantly
impact your project's architecture and design.

+--------------------------+---------+----------------+-------------+-------------+-------------+
| RULE                     | STD LIB | BASE PACKAGE   | FIRST PARTY | THIRD PARTY | FUTURE [#]_ |
+==========================+=========+================+=============+=============+=============+
| std-lib-only             | X       |                |             |             | X           |
+--------------------------+---------+----------------+-------------+-------------+-------------+
| project-only             | X       | X              | X           |             | X           |
+--------------------------+---------+----------------+-------------+-------------+-------------+
| base-package-only [#]_   | X       | X              |             |             | X           |
+--------------------------+---------+----------------+-------------+-------------+-------------+
| first-party-only         | X       |                | X           |             | X           |
+--------------------------+---------+----------------+-------------+-------------+-------------+
| third-party-only         | X       |                |             | X           | X           |
+--------------------------+---------+----------------+-------------+-------------+-------------+
| standalone-modules [#]_  | X       | X              |             | X           | X           |
+--------------------------+---------+----------------+-------------+-------------+-------------+


.. [#] To restrict future imports, use the
    `--restrict-future-imports` flag.
.. [#] Technically base package imports are "First Party" imports,
    but in this case we want to make a distinction between
    the top-level package and the rest of the project.
.. [#] The difference between third-party only and standalone,
    is that standalone allows imports from within the standalone
    module/package, while third-party only does not.


**Plugin Options: Project Import Rules (PIR)**
----------------------------------------------

Project Import Rules (PIR) allow you to define and enforce
import rules at a project level.

There are also several flags available to restrict specific
types of imports. Project import restriction flags:

============================  ==============================================================
 Project Import Rule           Description
============================  ==============================================================
restrict-relative-imports       This flag prevents the usage of relative imports.
                                Relative imports allow for modules to be imported
                                relative to the current module's location. This can
                                sometimes lead to confusion or unintended behavior,
                                especially in larger code bases.
                                Enabled by default. This is a boolean option, and
                                can be set to True or False (e.g., flag = True).

restrict-local-scope-imports    This flag restricts local scope imports, preventing
                                the import of modules or specific functions within
                                a particular scope, such as inside a function or
                                method. It enforces that all imports occur at the
                                top-level of the file, promoting code clarity and
                                consistency.
                                Enabled by default. This is a boolean option, and
                                can be set to True or False (e.g., flag = True).


restrict-conditional-imports    This flag restricts the use of conditional imports.
                                Conditional imports are imports that occur within an
                                if statement or similar control structure. These can
                                potentially lead to inconsistent behavior, as
                                whether or not a module is imported may depend on
                                runtime conditions.
                                Disabled by default. This is a boolean option, and
                                can be set to True or False (e.g., flag = True).

restrict-dynamic-imports        This flag restricts the use of dynamic imports,
                                which are imports that occur within a function or
                                method. These can be hard to track and may cause
                                unexpected behavior, as the availability of a module
                                may depend on the specific execution path through
                                the code.
                                Enabled by default. This is a boolean option, and
                                can be set to True or False (e.g., flag = True).

restrict-private-imports        This flag restricts the import of private modules
                                (those that start with an underscore). Importing
                                these modules can lead to instability, as they're
                                intended for internal use within a package and may
                                change without warning. Although, there are no
                                truly private modules/functions/methods in Python,
                                this flag can be
                                Enabled by default. This is a boolean option, and
                                can be set to True or False (e.g., flag = True).

restrict-wildcard-imports       This flag restricts the use of wildcard imports
                                (e.g., `from module import *`). These imports can
                                lead to confusion, as it's unclear which names are
                                being imported, and they can potentially overwrite
                                existing names without warning.
                                Enabled by default. This is a boolean option, and
                                can be set to True or False (e.g., flag = True).

restrict-aliased-imports        This flag restricts the import of modules under an
                                alias (e.g., import numpy as np). While convenient,
                                this can sometimes lead to confusion, especially
                                for less common libraries or non-standard aliases.
                                Given the ubiquity of certain aliases (e.g., np for
                                numpy).
                                Disabled by default. This is a boolean option, and
                                can be set to True or False (e.g., flag = True).

restrict-future-imports         This flag restricts the use of `from __future__
                                import`. These imports are used to enable features
                                that will be standard in future versions of Python,
                                but their use can potentially cause confusion or
                                compatibility issues.
                                Disabled by default. This is a boolean option, and
                                can be set to True or False (e.g., flag = True).

restrict-init-imports           This flag restricts imports from `__init__.py` files.
                                Importing from these files can sometimes lead to
                                confusing circular dependencies or other unexpected
                                behavior.
                                Enabled by default. This is a boolean option, and
                                can be set to True or False (e.g., flag = True).

restrict-main-imports           This flag restricts imports from `__main__.py`
                                files. Importing from a `__main__.py` file
                                is generally not considered best practice in
                                Python development. The `__main__.py` file is
                                typically used to define the entry point for
                                a package when it's executed as a script.
                                It's designed to contain code that kicks off
                                the execution of the program, not to define
                                reusable functions or classes.
                                Enabled by default. This is a boolean option, and
                                can be set to True or False (e.g., flag = True).

restrict-test-imports           This flag restricts imports from test files and
                                the tests directory. This can be used to enforce
                                separation of testing and production code.
                                Enabled by default. This is a boolean option, and
                                can be set to True or False (e.g., flag = True).

restrict-conftest-imports       This flag restricts imports within pytest's
                                conftest.py files. These files are used to define
                                fixtures and other setup code for tests, and
                                imports within them can potentially lead to
                                unexpected behavior.
                                Enabled by default. This is a boolean option, and
                                can be set to True or False (e.g., flag = True).

top-level-only-imports          This flag would enforce that all import statements
                                only refer to top-level modules. This could be used
                                in a project where the structure is intended to be
                                flat, with all modules at the top level.
                                NOT IMPLEMENTED.
============================  ==============================================================


These flags help maintain clean and clear import structures
by preventing certain types of potentially problematic
imports. For example, you may want to prevent relative
imports, which can make code harder to understand, or
wildcard imports, which can pollute the namespace. Each of
these flags can be enabled or disabled independently,
allowing for fine-grained control over your project's import
structure.

Restrict Relative Imports
~~~~~~~~~~~~~~~~~~~~~~~~~

Relative imports in Python allow you to import modules or
specific objects from modules within the same package
hierarchy, using dots (`.`) to represent the relative path.

By default, the `--restrict-relative-imports` flag is
enabled, prohibiting the use of relative imports. Modules
must instead utilize absolute imports, specifying the full
path to the target module, starting from the top-level
package.

To enforce this restriction and disable relative imports
for your project, you can configure the following setting:

.. code-block:: cfg

    [flake8]
    restrict_relative_imports = True

With this configuration, any relative imports encountered
in your project will be flagged by the linter, guiding you
to use absolute imports instead.


Restrict Local Scope Imports
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Local scope imports refer to the practice of importing
modules or specific objects within a confined scope, such
as inside a function or method. While this can allow for
more granular control over imports, it may lead to code
that is less clear and consistent.

The `--restrict-local-scope-imports` flag is designed to
prevent such imports, enforcing that all imports occur at
the top-level of the file. By centralizing imports, it
promotes code clarity and consistency across the project.

This restriction is turned on by default, meaning that any
local scope imports will be flagged by the linter. If you
wish to adhere to this best practice, ensure that all
imports are declared at the top-level of your files, rather
than within specific functions or methods.

.. code-block:: cfg

    [flake8]
    restrict_local_scope_imports = True

With this configuration, the linter will guide you to
organize your imports at the top-level, fostering a more
readable and maintainable codebase.

Restrict Conditional Imports
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Conditional imports in Python refer to the practice of
importing modules or specific symbols based on certain
conditions or runtime logic. These imports can be found
inside control structures like `if` statements.

The `--restrict-conditional-imports` flag aims to limit
the use of these imports, as they can potentially lead to
inconsistent behavior. The importation of a module might
depend on varying runtime conditions, leading to unexpected
outcomes.

This restriction is turned off by default, allowing for
conditional imports. However, considering the potential
risks and complexities, you may choose to enable this flag:

.. code-block:: cfg

    [flake8]
    restrict_conditional_imports = True

By restricting conditional imports, you can foster a more
predictable and manageable codebase.

Restrict Dynamic Imports
~~~~~~~~~~~~~~~~~~~~~~~~

Dynamic imports in Python involve importing modules or
specific symbols within a function or method. Such imports
can be challenging to track and may result in unexpected
behavior, as the availability of a module may hinge on the
specific execution path.

The `--restrict-dynamic-imports` flag is designed to
prevent these imports, promoting a more stable and
transparent code structure. This restriction is turned on
by default, emphasizing the importance of predictability
in code execution.

.. code-block:: cfg

    [flake8]
    restrict_dynamic_imports = True

By enforcing this rule, you encourage a more coherent
and traceable import structure, enhancing code reliability.

Restrict Private Imports
~~~~~~~~~~~~~~~~~~~~~~~~

Private modules in Python are typically those that begin
with an underscore (`_`). These modules are meant for
internal use within a package, and importing them can lead
to instability, as they may change without notice.

The `--restrict-private-imports` flag limits the import of
private modules, preserving the stability of your code.
Although Python doesn't truly enforce private access,
this flag provides a layer of protection. It is turned on
by default, reflecting a best-practice approach.

.. code-block:: cfg

    [flake8]
    restrict_private_imports = True

By restricting the import of private modules, you align
with community conventions and safeguard your code from
potential instabilities related to internal package changes.


Restrict Wildcard Imports
~~~~~~~~~~~~~~~~~~~~~~~~~

Wildcard imports in Python, expressed as `from module
import *`, bring all symbols from a module into the
current namespace. While convenient, these imports can
lead to confusion, as it becomes unclear which names are
being imported. Furthermore, they may inadvertently
overwrite existing names.

The `--restrict-wildcard-imports` flag is designed to
prohibit these imports, fostering greater code clarity
and safety. This flag is turned on by default, reflecting
a standard practice in code organization.

.. code-block:: cfg

    [flake8]
    restrict_wildcard_imports = True

By restricting wildcard imports, you promote a more
transparent and manageable code structure, enhancing
maintainability.


Restrict Aliased Imports
~~~~~~~~~~~~~~~~~~~~~~~~

Aliased imports, such as `import numpy as np`, allow
modules or specific symbols to be imported under a
different name. While often convenient, especially for
widely recognized aliases, they can sometimes cause
confusion, particularly with non-standard or
unconventional aliases.

The `--restrict-aliased-imports` flag aims to limit this
practice, although it is turned off by default,
acknowledging the common usage of standard aliases.

.. code-block:: cfg

    [flake8]
    restrict_aliased_imports = False

While aliasing has its benefits, particularly with widely
accepted conventions, this flag provides an option for
those who prefer to maintain a stricter naming policy.


Restrict Future Imports
~~~~~~~~~~~~~~~~~~~~~~~

Future imports in Python, expressed as `from __future__
import`, enable features that will become standard in
upcoming versions of Python. While they facilitate
forward compatibility, their use might also introduce
confusion or compatibility challenges.

The `--restrict-future-imports` flag allows you to limit
the use of future imports, providing a layer of control.
Thi