Skip to content

Add __all__ to __init__.py for type checker re-export compatibility#381

Merged
t20100 merged 2 commits intosilx-kit:mainfrom
riccardoratta:patch-1
Apr 27, 2026
Merged

Add __all__ to __init__.py for type checker re-export compatibility#381
t20100 merged 2 commits intosilx-kit:mainfrom
riccardoratta:patch-1

Conversation

@riccardoratta
Copy link
Copy Markdown
Contributor

Summary

Pyright/Pylance (and other PEP 484-compliant type checkers) do not treat from .module import Name in a package __init__.py as a public re-export. As a result, users of hdf5plugin with strict type checking enabled see errors such as:

"Blosc2" is not exported from module "hdf5plugin"

even though the import works correctly at runtime.

Root Cause

Pyright follows the rule defined in the typing spec: a name imported in a package's __init__.py is only considered a public re-export if it is:

  • re-imported using the from x import y as y form, or
  • listed in __all__.

The existing # noqa comments suppress linter warnings (e.g. flake8 F401) but have no effect on type checker re-export analysis.

Change

Update all public re-exports in __init__.py to use the explicit from ._filters import Blosc2 as Blosc2 form, which satisfies both type checkers and linters without requiring an __all__ declaration.

It has no runtime behaviour changes.

Copy link
Copy Markdown
Member

@t20100 t20100 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution!

"ZSTD_ID",
# Utilities
"FILTERS",
"PLUGIN_PATH",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from_filter_options is missing:

Suggested change
"PLUGIN_PATH",
"PLUGIN_PATH",
"from_filter_options",

Comment thread src/hdf5plugin/__init__.py Outdated
Comment on lines +77 to +88
# Filter ID constants
"BLOSC_ID",
"BLOSC2_ID",
"BSHUF_ID",
"BZIP2_ID",
"FCIDECOMP_ID",
"LZ4_ID",
"SPERR_ID",
"SZ_ID",
"SZ3_ID",
"ZFP_ID",
"ZSTD_ID",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I propose to remove the *_ID constants from __all__: The ids are accessible from the filter classes, e.g., Blosc2.filter_id, and I would consider deprecating the *_ID constants (not in this PR).

Suggested change
# Filter ID constants
"BLOSC_ID",
"BLOSC2_ID",
"BSHUF_ID",
"BZIP2_ID",
"FCIDECOMP_ID",
"LZ4_ID",
"SPERR_ID",
"SZ_ID",
"SZ3_ID",
"ZFP_ID",
"ZSTD_ID",

@riccardoratta
Copy link
Copy Markdown
Contributor Author

riccardoratta commented Apr 24, 2026

Done, I've added from_filter_options and removed the IDs.

@t20100 t20100 merged commit cfa4333 into silx-kit:main Apr 27, 2026
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants