Skip to content

Commit

Permalink
Ignore F401 for __init__.py files
Browse files Browse the repository at this point in the history
These files routinely import other modules without immediately using
them with the intention of making them available to the importing
module. Moreover, they are rarely even supposed to be used within the
same __init__.py file. Marking all of them 'noqa: F410' is redundant.
  • Loading branch information
mbr0wn committed Apr 4, 2024
1 parent 0606007 commit 988e74c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
10 changes: 9 additions & 1 deletion docs/Coding-Conventions.md
Original file line number Diff line number Diff line change
Expand Up @@ -858,13 +858,21 @@ import cheese_shop.brie

### [O.1.8]**DO NOT** Import definitions that are not used 💻

> 💻 This rule is enforced by error code F401
> 💻 This rule is enforced by error code F401, except in `__init__.py` files
ℹ️ `__init__.py` files routinely import other modules without using them and therefore are exempt from this rule.

```python
# Bad
import os # Assuming os is never used
```

```python
# Good - assuming we are in a __init__.py file
from .mysubmodule import spam, eggs # OK even if neither are used in this module
```


### [O.1.9]**DO NOT** Change an imported object's case 💻

> 💻 This rule is enforced by error codes N811, N812, N813, N814, N817
Expand Down
7 changes: 5 additions & 2 deletions ni_python_styleguide/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,11 @@ ignore =
# I101 - The names in your from import are in the wrong order. (Enforced by E401)
I101

# We want to ignore missing docstrings in test methods as they are self documenting
per-file-ignores= tests/**/test_*.py,tests/test_*.py:D100,D103,D102
per-file-ignores=
# We want to ignore missing docstrings in test methods as they are self documenting
tests/**/test_*.py,tests/test_*.py:D100,D103,D102
# __init__.py files import other modules routinely with directly using them
__init__.py:F401

# Flake8 includes mccabe by default.
# We have yet to evaluate it, so ignore the errors for now
Expand Down

0 comments on commit 988e74c

Please sign in to comment.