Skip to content

Lazy load model versions and enforce strict typing#36

Open
bact wants to merge 8 commits into
spdx:mainfrom
bact:reexport-binding-versions-2
Open

Lazy load model versions and enforce strict typing#36
bact wants to merge 8 commits into
spdx:mainfrom
bact:reexport-binding-versions-2

Conversation

@bact
Copy link
Copy Markdown
Collaborator

@bact bact commented Jun 5, 2026

This PR reimplements PR #31 (strict typing) and incorporates the suggestion to avoid loading all versions of the SPDX model upon import spdx_python_module. This saves memory and reduces load time (see #31 (comment)).

  • Pass mypy --strict
  • Versions are now lazy loaded
  • BREAKING CHANGE: from spdx_python_model import * now no longer load models

Existing code like this (from README) will still work:

# 1
import spdx_python_model

p = spdx_python_model.v3_0_1.Person()

This code will still work too:

# 2
from spdx_python_model import v3_0_1

p = v3_0_1.Person()

The only breaking change is this code:

# 3
from spdx_python_model import *

p = v3_0_1.Person()

The above code (no. 3) will no longer work because models (v3_0_1 etc) are no longer part of __all__.

bact added 2 commits June 5, 2026 20:20
Signed-off-by: Arthit Suriyawongkul <arthit@gmail.com>
Signed-off-by: Arthit Suriyawongkul <arthit@gmail.com>
@bact bact added the enhancement New feature or request label Jun 5, 2026
Signed-off-by: Arthit Suriyawongkul <arthit@gmail.com>
@bact bact changed the title Only load a model when explicitly imported Lazy load model versions and enforce strict typing Jun 5, 2026
Comment thread gen/generate-bindings Outdated
Comment thread src/spdx_python_model/__init__.py
Comment thread gen/generate-bindings Outdated
Comment thread src/spdx_python_model/__init__.py
Comment thread src/spdx_python_model/__init__.py
Comment thread src/spdx_python_model/__init__.py Outdated
bact and others added 4 commits June 6, 2026 00:59
Signed-off-by: Arthit Suriyawongkul <arthit@gmail.com>
Revise per code review

Co-Authored-By: Benjamin Robin <benjarobin@users.noreply.github.com>
Signed-off-by: Arthit Suriyawongkul <arthit@gmail.com>
Co-Authored-By: Benjamin Robin <benjarobin@users.noreply.github.com>
Signed-off-by: Arthit Suriyawongkul <arthit@gmail.com>
Copy link
Copy Markdown
Contributor

@benjarobin benjarobin left a comment

Choose a reason for hiding this comment

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

LGTM

Signed-off-by: Arthit Suriyawongkul <arthit@gmail.com>
@bact
Copy link
Copy Markdown
Collaborator Author

bact commented Jun 6, 2026

I just added a __version__ export which is a common dunder name to expose a version number.

https://peps.python.org/pep-0008/#module-level-dunder-names

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants