cattrs: cannot import name '_Union'

  • cattrs version: 0.9.0
  • Python version: 3.5.2
  • Operating System: ubuntu xenial64

Description

On a clean ubuntu VM, I pip3 install cattrs, and import cattr doesn’t seem to work.

Is something funny with the typing module in python 3.5.2 or something? It looks like travis tested Python 3.5, so I don’t understand how this happened.

What I Did

> vagrant init ubuntu/xenial64
...
> vagrant up
...
> vagrant ssh
...
vagrant@ubuntu-xenial:~$ wget https://bootstrap.pypa.io/get-pip.py
...
vagrant@ubuntu-xenial:~$ sudo python3 get-pip.py
...
vagrant@ubuntu-xenial:~$ pip3 install cattr
...
Successfully installed attrs-18.2.0 cattrs-0.9.0
vagrant@ubuntu-xenial:~$ python3
Python 3.5.2 (default, Nov 23 2017, 16:37:01)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cattr
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.5/dist-packages/cattr/__init__.py", line 2, in <module>
    from .converters import Converter, UnstructureStrategy
  File "/usr/local/lib/python3.5/dist-packages/cattr/converters.py", line 3, in
<module>
    from ._compat import (
  File "/usr/local/lib/python3.5/dist-packages/cattr/_compat.py", line 86, in <module>
    from typing import _Union
ImportError: cannot import name '_Union'
>>> import typing
>>> dir(typing)
['AbstractSet', 'Any', 'AnyMeta', 'AnyStr', 'AsyncIterable', 'AsyncIterator', 'Awaitable', 'BinaryIO', 'ByteString', 'CT', 'Callable', 'CallableMeta', 'Container', 'DefaultDict', 'Dict', 'Final', 'FrozenSet', 'Generator', 'Generic', 'GenericMeta', 'Hashable', 'IO', 'ItemsView', 'Iterable', 'Iterator', 'KT', 'KeysView', 'List', 'Mapping', 'MappingView', 'Match', 'MutableMapping', 'MutableSequence', 'MutableSet', 'NamedTuple', 'NewType', 'Optional', 'OptionalMeta', 'Pattern', 'Reversible', 'Sequence', 'Set', 'Sized', 'SupportsAbs', 'SupportsBytes', 'SupportsComplex', 'SupportsFloat', 'SupportsInt', 'SupportsRound', 'T', 'TYPE_CHECKING', 'T_co', 'T_contra', 'Text', 'TextIO', 'Tuple', 'TupleMeta', 'Type', 'TypeVar', 'TypingMeta', 'Union', 'UnionMeta', 'VT', 'VT_co', 'V_co', 'ValuesView', '_ForwardRef', '_FrozenSetMeta', '_G_base', '_Protocol', '_ProtocolMeta', '_TypeAlias', '__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', '_eval_type', '_geqv', '_get_defaults',
'_get_type_vars', '_gorg', '_next_in_mro', '_overload_dummy', '_qualname', '_type_check', '_type_repr', '_type_vars', 'abc', 'abstractmethod', 'abstractproperty', 'cast', 'collections', 'collections_abc', 'contextlib', 'functools', 'get_type_hints', 'io', 'no_type_check', 'no_type_check_decorator', 'overload', 're', 'stdlib_re', 'sys', 'types']

there is no '_Union' in there on my local system, I have python 3.6.4

Python 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:54:40) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import typing
>>> dir(typing)
['AbstractSet', 'Any', 'AnyStr', 'AsyncContextManager', 'AsyncGenerator', 'AsyncIterable', 'AsyncIterator', 'Awaitable', 'BinaryIO', 'ByteString', 'CT_co', 'Callable', 'CallableMeta', 'ChainMap', 'ClassVar', 'Collection', 'Container', 'ContextManager', 'Coroutine', 'Counter', 'DefaultDict', 'Deque', 'Dict', 'FrozenSet', 'Generator', 'Generic', 'GenericMeta', 'Hashable', 'IO', 'ItemsView', 'Iterable', 'Iterator', 'KT', 'KeysView', 'List', 'Mapping', 'MappingView', 'Match', 'MethodDescriptorType', 'MethodWrapperType', 'MutableMapping', 'MutableSequence', 'MutableSet', 'NamedTuple', 'NamedTupleMeta', 'NewType', 'NoReturn', 'Optional',
'Pattern', 'Reversible', 'Sequence', 'Set', 'Sized', 'SupportsAbs', 'SupportsBytes', 'SupportsComplex', 'SupportsFloat', 'SupportsInt', 'SupportsRound', 'T', 'TYPE_CHECKING', 'T_co', 'T_contra', 'Text', 'TextIO', 'Tuple', 'TupleMeta', 'Type', 'TypeVar', 'TypingMeta', 'Union', 'VT', 'VT_co', 'V_co', 'ValuesView', 'WrapperDescriptorType', '_Any', '_ClassVar', '_FinalTypingBase', '_ForwardRef', '_G_base', '_NoReturn', '_Optional', '_PY36', '_Protocol', '_ProtocolMeta', '_TypeAlias', '_TypingBase', '_TypingEllipsis', '_TypingEmpty', '_Union', '__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', '_allowed_types', '_check_generic', '_cleanups', '_collections_abc', '_eval_type', '_generic_new', '_get_defaults', '_get_type_vars', '_make_nmtuple', '_make_subclasshook', '_next_in_mro', '_no_slots_copy', '_overload_dummy', '_prohibited', '_qualname', '_remove_dups_flatten', '_replace_arg', '_special', '_subs_tree', '_tp_cache', '_trim_name', '_type_check', '_type_repr', '_type_vars', 'abc', 'abstractmethod', 'abstractproperty', 'cast', 'collections',
'collections_abc', 'contextlib', 'functools', 'get_type_hints', 'io', 'no_type_check', 'no_type_check_decorator', 'overload', 're', 'stdlib_re', 'sys', 'types']

That one has a '_Union'

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 15 (3 by maintainers)

Commits related to this issue

Most upvoted comments

This needs to be fixed, can’t run airflow!

The question is: when it gets released? As of https://github.com/Tinche/cattrs/issues/74 people start to release their forks on pypi already 😦 which indicates, that this project is more used than obvious…

Now that Python 3.8 is the default in Arch this breaks cattr for a larger amount of users. Is there any argument against the fixes proposed by @diefans and/or @llchan ?

FYI 3.8 has the same symptom, but the fix is to change the is_py37 check to something like

is_py37 = version_info[:2] >= (3, 7)

rather than the current strict equality.

Or better yet, find a different way to do those checks without reaching into private implementation details? Do we need to request additional functions from the typing/mypy guys?