Skip to content

Commit

Permalink
Ignore F401 for __init__.py files (#173)
Browse files Browse the repository at this point in the history
* 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 <matthew.shafer@ni.com>
  • Loading branch information
mbr0wn and mshafer-NI authored May 2, 2024
1 parent 11ec96f commit 45df40c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
8 changes: 8 additions & 0 deletions docs/Coding-Conventions.md
Original file line number Diff line number Diff line change
Expand Up @@ -860,11 +860,19 @@ import cheese_shop.brie

> 💻 This rule is enforced by error code F401
`__init__.py` files are an allowed exception because these are used to declare public APIs.

```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 routinely import other modules without 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 45df40c

Please sign in to comment.