Re-export binding versions to satisfied mypy --strict#31
Re-export binding versions to satisfied mypy --strict#31
Conversation
Modify the `__init__.py` generation so that bindings for each SPDX version will be re-exported. To fix mypy strict compatibility when enable strict=true in mypy. Currently this code: `from spdx_python_model import v3_0_1` will cause mypy (strict=true) error as: `Module "spdx_python_model" has no attribute "v3_0_1"` Signed-off-by: Arthit Suriyawongkul <arthit@gmail.com>
|
The generated # SPDX-License-Identifier: Apache-2.0
#
# Generated by generate-bindings at build time. DO NOT EDIT.
"""SPDX model in Python."""
from .bindings import v3_0_1
from .version import VERSION
__all__ = [
"VERSION",
"v3_0_1",
]The generated # SPDX-License-Identifier: Apache-2.0
#
# Generated by generate-bindings at build time. DO NOT EDIT.
"""SPDX model in Python — all supported SPDX versions."""
from . import v3_0_1
__all__ = [
"v3_0_1",
]The generated actual bindings will be handled normally by shacl2code. |
|
I never noticed that, but is it a good ideal to load all binding versions from |
|
The current implementation loads We can also ask the developers to do
instead. That would be cleaner. |
|
This is a breaking change. I am proposing to remove the And I prefer to change that as soon as possible. This way we are not living with this "issue" forever. |
We have several spdx-python-model/src/spdx_python_model/__init__.py Lines 5 to 6 in 4f82f94 (Btw, this file is not part of current generation script, it will be used as-is. |
That the file will be overwritten at build time. Signed-off-by: Arthit Suriyawongkul <arthit@gmail.com>
|
The goal is when doing If I am not mistaken, when doing |
Agree and want to see that too. The question here is how to deal with a statement like:
If we are to allow it (like it currently is), we need to import and re-export We can remove the import/re-export there, but that will be a breaking change for people who do import (Anyway, since we are in 0.0.x version line, breaking changes should not be a surprise, if we need to) |
|
As I said, this is a (major) breaking change. |
|
Thank you. I will open another PR to propose an alternative from this PR, based on our discussion. It will introduce a breaking change (while this PR will not). The goal is to improve resource efficiency (when SPDX versions are growing) by moving away from import * in init.py, so we only load modules as needed instead of loading unused components. (Note that this is not currently an issue because there's only one version to load and by definition nothing is unused). It should also keep typing annotation accurate (as intended similarly in this PR). |
Modify the
__init__.pygeneration so that bindings for each SPDX version will be re-exported.To fix mypy compatibility when
strict=true.Currently this code:
from spdx_python_model import v3_0_1will cause mypy (strict=true) error as:
Module "spdx_python_model" has no attribute "v3_0_1"