Error: Union Type Hint(operator "|") in Python 3.10

16 views
Skip to first unread message

Junho Lee

unread,
Jan 26, 2023, 1:30:35 AM1/26/23
to sphinx-users
Hello Sphinx community,

I have gotten a TypeError when I build sphinx with autodoc.

"Union" type hint replaced operator "|" in Python 3.10. And, I add into autodoc_mock_imports  for dbus package which has external dependencies.

So, in my case, there is an method`s arguments:
foo_arg: dbus.UInt16 | dbus.Array
The Sphinx make TypeError when I build sphinx with autodoc:
TypeError: unsupported operand type(s) for |: 'UInt16' and 'Array'
How can I resolve this problem?

My environment:
Python: 3.10.6
Sphinx: 5.0.2 (but there is still problem when I upgraded 6.1.3)
     conf.py:
         extensions = ["sphinx.ext.autodoc"]
         autodoc_mock_imports = ["gi", "dbus"]


Let me know what you think or if anything is missing.

Regards,
Junho

Junho Lee

unread,
Jan 26, 2023, 2:55:38 AM1/26/23
to sphinx-users
I found an solution which is using typing.Union.
But it makes inconsistency due to difference from the whole application of PEP 604.

Regards,
Junho

2023년 1월 26일 목요일 오후 3시 30분 35초 UTC+9에 Junho Lee님이 작성:
Reply all
Reply to author
Forward
0 new messages