Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add rule for 'local_imports'#695

Merged
emdoyle merged 7 commits intomainfrom
rule-ignore-local-imports
Mar 19, 2025
Merged

Add rule for 'local_imports'#695
emdoyle merged 7 commits intomainfrom
rule-ignore-local-imports

Conversation

@emdoyle
Copy link
Contributor

@emdoyle emdoyle commented Mar 19, 2025

Fixes: #599

This PR adds a 'rule' configuration option called rules.local_imports. It can be set as usual:

[rules]
local_imports = "error"  # | "warn" | "off"

This rule applies to any Diagnostic that would have been emitted due to an import which is not at the global scope. This includes imports within 'if' statements, functions, classes, or other control structures.

def fun():
    # this is a local import
    from mymodule import api
    api()

The default setting is "error", since today local imports are treated identically to global imports and will produce dependency/interface errors.

Setting local_imports = "off" means that you will no longer see Diagnostics for local imports, even when they violate dependency rules or public interfaces.

@emdoyle emdoyle marked this pull request as ready for review March 19, 2025 17:17
@emdoyle emdoyle merged commit 5bf9892 into main Mar 19, 2025
8 of 11 checks passed
@emdoyle emdoyle deleted the rule-ignore-local-imports branch March 19, 2025 17:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Option to ignore non-global imports

1 participant