(Hi! Apologies for the drive-by comments, hopefully they won't be complete noise. Butting in hoping to clarify things at best, stand corrected at worst)
Bruno Haible <br...@clisp.org> writes: >> Python has added a lot of interesting type hinting stuff over the past >> few years [3]. > > Interesting. Feel free to use this syntax where you find it appropriate. > > I feel it would make sense to use for function returns. For function arguments > we already have type tests in the essential places. I would consider type tests (assuming you mean something along the lines of 'type(arg) is Sometype' or 'isinstance(arg, Sometype)') and type annotations somewhat orthogonal: * the former provide some runtime sanity-checking, * the latter are ineffective at runtime, and exist mainly for the programmer's benefit (IDE hints for completion, documentation, linting, etc). (Though linters like mypy do _also_ pick up on the former) >> Reading the union types was a bit confusing at first >> since I didn't know they were added [4]. > > Probably they would apply here: > > def cleaner(sequence): > > could become > > def cleaner(sequence) -> str | list(str): > > But since they are only supported starting with Python 3.10, and Python 3.10 > is not on board of e.g. CentOS 8 or Ubuntu 20.04 [1], I would find it too > early > to use this syntax now (except in comments, of course). 'from __future__ import annotations', available since Python 3.7 [1], allows older Pythons to ignore type-hint syntax sophistications brought by newer Pythons. So if Python 3.7 is acceptable as a minimum version (it seems available in the distro releases you mention), you would be able to start using this union syntax. [1] https://docs.python.org/3/library/__future__.html