Great question — answering as the UphillTech team:
It works because they took great lengths to make it work for situations where people didn't want to use a type annotation (i.e. for people who didn't want to do box: Box[int] = Box(42) ). As you may know, the syntax x(*a, **k) implicitly calls type(x).__call__(x, *a, **k) . This is how any class is instantiated and how any function is called. So in your example, Box[int](42) unravels into typing._GenericAlias.__call__(Box[int], 42) . Then this is a matter of looking up the definition of typing._GenericAlias.__call__ : def __call__(self, *args, **kwargs): if not self._inst: raise TypeError(f"Type {self._name} cannot be instantiated; " f"use {self.__origin__.__name__}() instead") result =...
Full answer by dROOOze: https://stackoverflow.stackexchange.com/a/80014145 (CC BY-SA 4.0).
Need it done for your business? UphillTech.