0

Here's a trivial example of what I'm looking for. Suppose you want a function that returns an iterable of the same type as x for each argument x to the function. So without type signatures, it looks like this;

def trivial(*args):
    return tuple([[arg] for arg in args])

How would I type a function like this? Is this supported?

Samwise
  • 68,105
  • 3
  • 30
  • 44
  • Is this the same question: https://stackoverflow.com/questions/37031928/type-annotations-for-args-and-kwargs? – Jamie Doornbos Dec 16 '22 at 23:35
  • 3
    I don't think you can type that function safely. I'd rethink the interface to make the typing easier, personally -- iterables of mixed types are awkward to work with in general. – Samwise Dec 16 '22 at 23:39
  • 1
    @Samwise Is it just me, or have questions about type annotations exploded in the last few months? Did something happen recently to make everyone want to express complex type relationships? – Barmar Dec 16 '22 at 23:44
  • @JamieDoornbos That question is about type hints for the arguments, this is about the return value. – Barmar Dec 16 '22 at 23:44
  • 1
    The kind of type relationship that this wants to express is something like `Tuple[A, B, C, ...] -> Tuple[List[A], List[B], List[C], ...]` which is something I don't think you can express even without bringing the normal difficulties of typing `*args` into it. – Samwise Dec 17 '22 at 00:01

0 Answers0