From abea36c506ca3480fe116489752119c5712ea022 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Val=C3=A9rian=20Rey?= Date: Fri, 26 Dec 2025 20:43:19 +0100 Subject: [PATCH 1/3] feat: Add --- .pre-commit-config.yaml | 1 - CHANGELOG.md | 4 +++ src/torchjd/aggregation/__init__.py | 36 ++++++++++++++++++++++ src/torchjd/autogram/__init__.py | 2 ++ src/torchjd/autojac/__init__.py | 2 ++ src/torchjd/autojac/_transform/__init__.py | 16 ++++++++++ 6 files changed, 60 insertions(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 32099e57..b03a69f8 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -15,7 +15,6 @@ repos: - id: flake8 # Check style and syntax. Does not modify code, issues have to be solved manually. args: [ '--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. - '--per-file-ignores=*/__init__.py:F401', # Ignore module imported but unused problems in __init__.py files. ] - repo: https://github.com/pycqa/isort diff --git a/CHANGELOG.md b/CHANGELOG.md index d1873e09..76bbad54 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ changes that do not affect the user. ## [Unreleased] +### Added + +- Added `__all__` in the `__init__.py` of packages. This should prevent PyLance from triggering warnings when importing from `torchjd`. + ## [0.8.0] - 2025-11-13 ### Added diff --git a/src/torchjd/aggregation/__init__.py b/src/torchjd/aggregation/__init__.py index 19dc060f..9eed9bf7 100644 --- a/src/torchjd/aggregation/__init__.py +++ b/src/torchjd/aggregation/__init__.py @@ -80,12 +80,48 @@ ) from ._weighting_bases import GeneralizedWeighting, Weighting +__all__ = [ + "Aggregator", + "AlignedMTL", + "AlignedMTLWeighting", + "ConFIG", + "Constant", + "ConstantWeighting", + "DualProj", + "DualProjWeighting", + "Flattening", + "GeneralizedWeighting", + "GradDrop", + "IMTLG", + "IMTLGWeighting", + "Krum", + "KrumWeighting", + "Mean", + "MeanWeighting", + "MGDA", + "MGDAWeighting", + "PCGrad", + "PCGradWeighting", + "Random", + "RandomWeighting", + "Sum", + "SumWeighting", + "TrimmedMean", + "UPGrad", + "UPGradWeighting", + "Weighting", +] + try: from ._cagrad import CAGrad, CAGradWeighting + + __all__ += ["CAGrad", "CAGradWeighting"] except _OptionalDepsNotInstalledError: # The required dependencies are not installed pass try: from ._nash_mtl import NashMTL + + __all__ += ["NashMTL"] except _OptionalDepsNotInstalledError: # The required dependencies are not installed pass diff --git a/src/torchjd/autogram/__init__.py b/src/torchjd/autogram/__init__.py index 0f8b29b9..84c9b2ab 100644 --- a/src/torchjd/autogram/__init__.py +++ b/src/torchjd/autogram/__init__.py @@ -28,3 +28,5 @@ """ from ._engine import Engine + +__all__ = ["Engine"] diff --git a/src/torchjd/autojac/__init__.py b/src/torchjd/autojac/__init__.py index 7ffc1c51..846c062c 100644 --- a/src/torchjd/autojac/__init__.py +++ b/src/torchjd/autojac/__init__.py @@ -7,3 +7,5 @@ from ._backward import backward from ._mtl_backward import mtl_backward + +__all__ = ["backward", "mtl_backward"] diff --git a/src/torchjd/autojac/_transform/__init__.py b/src/torchjd/autojac/_transform/__init__.py index cb39543b..46be392d 100644 --- a/src/torchjd/autojac/_transform/__init__.py +++ b/src/torchjd/autojac/_transform/__init__.py @@ -8,3 +8,19 @@ from ._ordered_set import OrderedSet from ._select import Select from ._stack import Stack + +__all__ = [ + "Accumulate", + "Aggregate", + "Composition", + "Conjunction", + "Diagonalize", + "Grad", + "Init", + "Jac", + "OrderedSet", + "RequirementError", + "Select", + "Stack", + "Transform", +] From 7388054c509ddbe0cee26099be556b8d176972f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Val=C3=A9rian=20Rey?= Date: Fri, 26 Dec 2025 21:02:55 +0100 Subject: [PATCH 2/3] Add :no-members: in index.rst to prevent double inclusion of modules --- docs/source/docs/autogram/index.rst | 2 +- docs/source/docs/autojac/index.rst | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/docs/source/docs/autogram/index.rst b/docs/source/docs/autogram/index.rst index 75fe70fe..228eaebb 100644 --- a/docs/source/docs/autogram/index.rst +++ b/docs/source/docs/autogram/index.rst @@ -3,7 +3,7 @@ autogram .. automodule:: torchjd.autogram - :members: + :no-members: .. toctree:: :hidden: diff --git a/docs/source/docs/autojac/index.rst b/docs/source/docs/autojac/index.rst index 180d25bc..4ca478cf 100644 --- a/docs/source/docs/autojac/index.rst +++ b/docs/source/docs/autojac/index.rst @@ -2,8 +2,7 @@ autojac ======= .. automodule:: torchjd.autojac - :members: - + :no-members: .. toctree:: :hidden: From c13086c99bd4622e29fe772c5c280198871e739e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Val=C3=A9rian=20Rey?= Date: Fri, 26 Dec 2025 21:03:58 +0100 Subject: [PATCH 3/3] Fix formatting --- docs/source/docs/autogram/index.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/source/docs/autogram/index.rst b/docs/source/docs/autogram/index.rst index 228eaebb..68ed6163 100644 --- a/docs/source/docs/autogram/index.rst +++ b/docs/source/docs/autogram/index.rst @@ -1,7 +1,6 @@ autogram ======== - .. automodule:: torchjd.autogram :no-members: