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

Literal-types #2261

Merged
merged 2 commits into from
Oct 14, 2021
Merged

Literal-types #2261

merged 2 commits into from
Oct 14, 2021

Conversation

janosh
Copy link
Member

@janosh janosh commented Oct 13, 2021

Follow up to #2247.

@CompRhys informed me that due to #2247, Pymatgen is no longer installable in Google Colab which is locked to Python 3.7 while typing.Literal was only added in Python 3.8.

There's a relatively recent but quiet issue tracking the ability to select different Python versions in Colab: googlecolab/colabtools#2165

In the meantime though, I assume Pymatgen wants to keep supporting Google Colab. I think the best solution for that would be to protect Literal imports with

from typing import TYPE_CHECKING

if TYPE_CHECKING:
    from typing import Literal

and then use the string form "Literal" in type hints. Happy to add those changes to this PR if that's acceptable.

@mkhorton
Copy link
Member

You can install typing_extensions, which is actually already a requirement of pymatgen if you're running in Python 3.7.

The correct way of resolving this is following this example:

if sys.version_info >= (3, 8):
from typing import Literal
else:
from typing_extensions import Literal

Apologies, I should have mentioned this in your earlier PR but forgot.

@janosh
Copy link
Member Author

janosh commented Oct 13, 2021

@mkhorton Thanks for that advice. Changed all the Literal imports from #2247.

@CompRhys
Copy link
Contributor

pulled this branch everything seems to work

@mkhorton mkhorton merged commit dffcac6 into materialsproject:master Oct 14, 2021
@mkhorton
Copy link
Member

Thanks both!

@janosh janosh deleted the literal-types branch October 14, 2021 19:51
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

3 participants