redruin1 / factorio-draftsman

A complete, well-tested, and up-to-date module to manipulate Factorio blueprint strings. Compatible with mods.
MIT License
94 stars 17 forks source link

ImportError: cannot import name 'Literal' from 'typing' #30

Closed WidAmi closed 2 years ago

WidAmi commented 2 years ago

I get the following error trying to import draftsman. This is on Mac OS using Python 3.7. Draftsman version 0.9.6

ImportError: cannot import name 'Literal' from 'typing' (/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/typing.py)

I can work around this with this but I'm not sure that's a completely compatible fix. Most fixes on the web put something similar into the library itself.

from typing_extensions import Literal
import typing
typing.Literal = Literal
from draftsman import utils
from draftsman.blueprintable import get_blueprintable_from_string
redruin1 commented 2 years ago

I forgot to put typing_extensions in setup.py; this only affects versions of Python prior to 3.8. Theoretically all you should have to do is run pip install typing_extensions in your environment and it should fix itself. The updated setup.py will be in version 0.9.7.

WidAmi commented 2 years ago

It looks like splitter.py needs an edit to handle finding Literal either in typing or typing_extensions.

Stack Overflow suggests:

try:
    from typing import Literal
except ImportError:
    from typing_extensions import Literal
redruin1 commented 2 years ago

Should be fixed as of 1.0.0.