Skip to content

Commit 45df40c

Browse files
mbr0wnmshafer-NI
andauthored
Ignore F401 for __init__.py files (#173)
* Ignore F401 for __init__.py files 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. * Update docs/Coding-Conventions.md --------- Co-authored-by: mshafer-NI <[email protected]>
1 parent 11ec96f commit 45df40c

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

docs/Coding-Conventions.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -860,11 +860,19 @@ import cheese_shop.brie
860860

861861
> 💻 This rule is enforced by error code F401
862862
863+
`__init__.py` files are an allowed exception because these are used to declare public APIs.
864+
863865
```python
864866
# Bad
865867
import os # Assuming os is never used
866868
```
867869

870+
```python
871+
# Good - assuming we are in a __init__.py file
872+
from .mysubmodule import spam, eggs # OK even if neither are used in this module
873+
```
874+
875+
868876
### [O.1.9]**DO NOT** Change an imported object's case 💻
869877

870878
> 💻 This rule is enforced by error codes N811, N812, N813, N814, N817

ni_python_styleguide/config.ini

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,11 @@ ignore =
112112
# I101 - The names in your from import are in the wrong order. (Enforced by E401)
113113
I101
114114

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

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

0 commit comments

Comments
 (0)