Skip to content
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

DM-33814: Add type annotations to version.py #105

Merged
merged 3 commits into from
Feb 28, 2022
Merged

DM-33814: Add type annotations to version.py #105

merged 3 commits into from
Feb 28, 2022

Conversation

timj
Copy link
Member

@timj timj commented Feb 24, 2022

Also fixed a warning from use of the deprecated imp package.

__version_info__ is not included because that is a Tuple
and the import from typing should only happen if __version__info__
is being included.
submodule_search_locations=None,
loader=loader)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
Copy link
Member

Choose a reason for hiding this comment

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

FWIW, I'm not sure why I used imp here in the first place; it's certainly conceivable that something like this would also work:

with open(filename, "r") as buffer:
    vars = {}
    exec(buffer.read(), vars)
module = SimpleNamespace(**vars)  # not really a module, but close enough

Copy link
Member Author

Choose a reason for hiding this comment

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

Incredibly the way I'm doing it seems to be the documented approach. I couldn't believe it myself. I'm sure you used imp because it was the default old way to do it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Pondering this, I think I'm fine with the documented importlib approach rather than using SimpleNamespace.

@timj timj merged commit 26c60a2 into main Feb 28, 2022
@timj timj deleted the tickets/DM-33814 branch February 28, 2022 16:38
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.

None yet

2 participants