Skip to content

Fix submodule visibility in country modules #479

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

philmas
Copy link

@philmas philmas commented Aug 5, 2025

Add explicit imports to init.py files for all country modules to make submodules visible via dir() function. This resolves the issue where submodules like stdnum.gb.nhs, stdnum.us.ssn, etc. were not discoverable through introspection despite being importable directly.

Changes:

  • Added explicit 'from stdnum.{country} import {module}' statements
  • Added '# noqa: F401' comments to suppress unused import warnings
  • Ensures all submodules are now visible in dir() output
  • Maintains backward compatibility for direct imports

Fixes module discoverability for all country-specific validation modules.

Add explicit imports to __init__.py files for all country modules to make
submodules visible via dir() function. This resolves the issue where
submodules like stdnum.gb.nhs, stdnum.us.ssn, etc. were not discoverable
through introspection despite being importable directly.

Changes:
- Added explicit 'from stdnum.{country} import {module}' statements
- Added '# noqa: F401' comments to suppress unused import warnings
- Ensures all submodules are now visible in dir() output
- Maintains backward compatibility for direct imports

Fixes module discoverability for all country-specific validation modules.
@arthurdejong
Copy link
Owner

Hi @philmas,

Thanks for your suggestion. I don't think I fully understand the use case behind the change. Introspection works fine with pkgutil.walk_packages() and there is also already a stdnum.util.get_number_modules() function that can help you with that.

For example, to get all the UK number format modules, you can do:

>>> from stdnum.util import get_number_modules
>>> [module.__name__ for module in get_number_modules('stdnum.gb')]
['stdnum.gb.nhs', 'stdnum.gb.sedol', 'stdnum.gb.upn', 'stdnum.gb.utr', 'stdnum.gb.vat']

(by default it will list all the number formats)

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