About 50 results
Open links in new tab
  1. python - How to use typing.Annotated - Stack Overflow

    Apr 17, 2022 · I'm having a hard time understanding what typing.Annotated is good for from the documentation and an even harder time finding explanations/examples outside the documentation. …

  2. How to specify multiple types using type-hints - Stack Overflow

    Sep 20, 2025 · 724 I have a function in python that can either return a bool or a list. Is there a way to specify the types using type hints? For example, is this the correct way to do it?

  3. Type hinting tuples in Python - Stack Overflow

    Nov 28, 2017 · def func(var: list[int]): # do something func([1]) # would be fine func([1, 2]) # would also be fine func([1, 2, 3]) # would also be fine That's consequentially, in a way, because of the type of …

  4. python - Using List/Tuple/etc. from typing vs directly referring type ...

    Sep 12, 2016 · 349 Until Python 3.9 added support for type hinting using standard collections, you had to use typing.Tuple and typing.List if you wanted to document what type the contents of the …

  5. python - How do I type hint a method with the type of the enclosing ...

    Introduced in Python 3.11, typing.Self refers to the type of the current instance, even if that type is a subclass of the class the annotation appears in. So if you have the following code:

  6. python - What is the correct way of using typing.Literal ... - Stack ...

    Oct 4, 2021 · What is the correct way of using typing.Literal? Asked 4 years, 5 months ago Modified 1 year, 6 months ago Viewed 18k times

  7. types - What does typing.cast do in Python? - Stack Overflow

    Jul 21, 2018 · What does typing.cast do in Python? Ask Question Asked 7 years, 7 months ago Modified 2 years ago

  8. what exactly is python typing.Callable? - Stack Overflow

    Feb 3, 2022 · 66 typing.Callable is the type you use to indicate a callable. Most python types that support the () operator are of the type collections.abc.Callable. Examples include functions, …

  9. Python `typing.cast` method vs colon type hints - Stack Overflow

    Oct 9, 2023 · What the difference between using the Python typing.cast method x = cast(str, x) compared with using type hints/colon notation/left hand side type annotation? x: str I've seen the use …

  10. How can I type hint a generator in Python 3? [duplicate]

    The Iterator, Generator, and Iterable are slightly different in details and carry different type of information, so understanding the difference might help choosing the correct one for your code: …