Typing module gone missing

What I’m trying to do:

Import some classes from the typing module. The following code has been working without incident for lo these many months:

from typing import Dict, Mapping, MutableMapping, List, Iterable, Any

Now suddenly my app is crashing on load because:

ImportError: No module named typing

What I’ve tried and what’s not working:

It was working just fine up until two days ago. :frowning:

Has the module typing been removed???

Heidi

Hi @heidi

Where is this code running? Is this on the client or the server, and in which version of Python?

Hi @daviesian ,

It is Python 3 running on the client.

HB

Thanks! We will investigate this and get back to you.

1 Like

Thanks, Ian. Much appreciated.

This is a sidetrack from your actual question, but I’m very curious how you make use of typing on the client side.

@hugetim :rofl: :rofl: :rofl: Sorry can’t answer that; it’s my partner’s code. He’s a little more (ahem) detailed oriented than I; I’m a weakly typed kinda gal!

Heidi

1 Like

We’ve had a look and this is the result of a skulpt update where function annotations that were previously ignored, now do something on the client.

try:
    from typing import Any, Dict
except:
    pass

def foo(x: Dict[Any]) -> None:
    pass

# Dict is not defined
# previously no error because the annotation was ignored by the compiler

The suggested fix related to this post with the following adjustments:

try:
    from typing import Any, Dict # works on the server
except ImportError:
    from .fake_typing import Any, Dict # works on the client side
# fake_typing module
class GenericAlias:
   def __getitem__(self, key):
        return self

Any = GenericAlias()
Dict = GenericAlias()


What happens to the annotations now?
def foo(x:str) -> None:
    pass

print(foo.__annotations__)
# {'x': str, 'return': None}

2 Likes