Skip to content

Commit cc0ce66

Browse files
authored
fix: Add __all__ in __init__.py files (#501)
* Add changelog entry * Update pre-commit config to warn about unused imports in __init__.py
1 parent c5b5a3e commit cc0ce66

File tree

8 files changed

+62
-5
lines changed

8 files changed

+62
-5
lines changed

.pre-commit-config.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ repos:
1515
- id: flake8 # Check style and syntax. Does not modify code, issues have to be solved manually.
1616
args: [
1717
'--ignore=E501,E203,W503,E402', # Ignore line length problems, space after colon problems, line break occurring before a binary operator problems, module level import not at top of file problems.
18-
'--per-file-ignores=*/__init__.py:F401', # Ignore module imported but unused problems in __init__.py files.
1918
]
2019

2120
- repo: https://github.com/pycqa/isort

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ changes that do not affect the user.
88

99
## [Unreleased]
1010

11+
### Added
12+
13+
- Added `__all__` in the `__init__.py` of packages. This should prevent PyLance from triggering warnings when importing from `torchjd`.
14+
1115
## [0.8.0] - 2025-11-13
1216

1317
### Added

docs/source/docs/autogram/index.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
autogram
22
========
33

4-
54
.. automodule:: torchjd.autogram
6-
:members:
5+
:no-members:
76

87
.. toctree::
98
:hidden:

docs/source/docs/autojac/index.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ autojac
22
=======
33

44
.. automodule:: torchjd.autojac
5-
:members:
6-
5+
:no-members:
76

87
.. toctree::
98
:hidden:

src/torchjd/aggregation/__init__.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,48 @@
8080
)
8181
from ._weighting_bases import GeneralizedWeighting, Weighting
8282

83+
__all__ = [
84+
"Aggregator",
85+
"AlignedMTL",
86+
"AlignedMTLWeighting",
87+
"ConFIG",
88+
"Constant",
89+
"ConstantWeighting",
90+
"DualProj",
91+
"DualProjWeighting",
92+
"Flattening",
93+
"GeneralizedWeighting",
94+
"GradDrop",
95+
"IMTLG",
96+
"IMTLGWeighting",
97+
"Krum",
98+
"KrumWeighting",
99+
"Mean",
100+
"MeanWeighting",
101+
"MGDA",
102+
"MGDAWeighting",
103+
"PCGrad",
104+
"PCGradWeighting",
105+
"Random",
106+
"RandomWeighting",
107+
"Sum",
108+
"SumWeighting",
109+
"TrimmedMean",
110+
"UPGrad",
111+
"UPGradWeighting",
112+
"Weighting",
113+
]
114+
83115
try:
84116
from ._cagrad import CAGrad, CAGradWeighting
117+
118+
__all__ += ["CAGrad", "CAGradWeighting"]
85119
except _OptionalDepsNotInstalledError: # The required dependencies are not installed
86120
pass
87121

88122
try:
89123
from ._nash_mtl import NashMTL
124+
125+
__all__ += ["NashMTL"]
90126
except _OptionalDepsNotInstalledError: # The required dependencies are not installed
91127
pass

src/torchjd/autogram/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,5 @@
2828
"""
2929

3030
from ._engine import Engine
31+
32+
__all__ = ["Engine"]

src/torchjd/autojac/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@
77

88
from ._backward import backward
99
from ._mtl_backward import mtl_backward
10+
11+
__all__ = ["backward", "mtl_backward"]

src/torchjd/autojac/_transform/__init__.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,19 @@
88
from ._ordered_set import OrderedSet
99
from ._select import Select
1010
from ._stack import Stack
11+
12+
__all__ = [
13+
"Accumulate",
14+
"Aggregate",
15+
"Composition",
16+
"Conjunction",
17+
"Diagonalize",
18+
"Grad",
19+
"Init",
20+
"Jac",
21+
"OrderedSet",
22+
"RequirementError",
23+
"Select",
24+
"Stack",
25+
"Transform",
26+
]

0 commit comments

Comments
 (0)