Type hints don't work with from __future__ import annotations and complex types

The following script device server fails for me because pytango cannot deduce the type of bar:

from __future__ import annotations

from tango.server import Device, attribute


class MyDevice(Device):
    @attribute
    def bar(self) -> str:
        return []

    @attribute
    def bar(self) -> list[str]:
        return []

I get the following output (with pytango 10.0.3):

> python test.py
Traceback (most recent call last):
  File "/home/tri/osl/skao/ska-tango-base.git/topic/wom-679-add-controller-interface/.v
env/lib64/python3.10/site-packages/tango/utils.py", line 533, in get_tango_type_format
    tango_type = TO_TANGO_TYPE[dtype]
KeyError: 'list[str]'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/tri/osl/skao/ska-tango-base.git/topic/wom-679-add-controller-interface/te
st.py", line 6, in <module>
    class MyDevice(Device):
  File "/home/tri/osl/skao/ska-tango-base.git/topic/wom-679-add-controller-interface/.v
env/lib64/python3.10/site-packages/tango/server.py", line 950, in __new__
    _init_tango_device_klass(cls, dct)
  File "/home/tri/osl/skao/ska-tango-base.git/topic/wom-679-add-controller-interface/.v
env/lib64/python3.10/site-packages/tango/server.py", line 889, in _init_tango_device_kl
ass
    tango_deviceclass_klass = __create_tango_deviceclass_klass(
  File "/home/tri/osl/skao/ska-tango-base.git/topic/wom-679-add-controller-interface/.v
env/lib64/python3.10/site-packages/tango/server.py", line 815, in __create_tango_device
class_klass
    __get_attribute_type_from_hint(
  File "/home/tri/osl/skao/ska-tango-base.git/topic/wom-679-add-controller-interface/.v
env/lib64/python3.10/site-packages/tango/server.py", line 305, in __get_attribute_type_
from_hint
    dtype, dformat, enum_labels = get_attribute_type_format(
  File "/home/tri/osl/skao/ska-tango-base.git/topic/wom-679-add-controller-interface/.v
env/lib64/python3.10/site-packages/tango/utils.py", line 509, in get_attribute_type_for
mat
    return *get_tango_type_format(dtype, dformat, "attribute"), enum_labels
  File "/home/tri/osl/skao/ska-tango-base.git/topic/wom-679-add-controller-interface/.v
env/lib64/python3.10/site-packages/tango/utils.py", line 535, in get_tango_type_format
    raise RuntimeError(
RuntimeError: Cannot translate list[str] to TANGO type. See documentation for the allow
ed types

I don't get an error if I either comment out the from __future__ ... line or if I comment out the bar attribute.

Edited Aug 19, 2025 by Anton Joubert
Assignee Loading
Time tracking Loading