0

Python 3.10 introduces new fancy ways to describe the type of a variable without the need to import typing like

list_of_string : list[str] = ["hey"]
optional_int_var : int | None = None

Is there a way to describe the wildcard type without importing typing.Any ?

Martin Faucheux
  • 884
  • 9
  • 26
  • 1
    I don't think so; `Any` fills a void that doesn't exist in a dynamically typed language. See [this answer](https://stackoverflow.com/posts/39817126/edit) regarding the different between `Any` and `object`. – chepner Mar 25 '22 at 16:29
  • Note that `list[int]` evaluates to the same thing as `List[int]`, even though `list` and `List` are distinct. `list[int]` is syntactic sugar for `list.__class_getitem__(int)`, with `__class_getitem__` being the new introduction in Python 3.10. It's not clear what would make a good candidate to evaluate to `typing.Any` in a similar way. – chepner Mar 25 '22 at 16:45
  • 2
    Currently no, you can refer to [this question](https://stackoverflow.com/questions/65120501/typing-any-in-python-3-9-and-pep-585-type-hinting-generics-in-standard-collect). – Char Mar 25 '22 at 17:03

0 Answers0