Git Product home page Git Product logo

Comments (2)

zen-xu avatar zen-xu commented on July 24, 2024

If TypeVarTuple supports list comprehension, that would be great

from typing import Generic
from typing import TypeVar
from typing import TypeVarTuple


_T = TypeVar("_T")
_Ts = TypeVarTuple("_Ts")


class ObjectRef(Generic[_T]): ...

def put(items: tuple[*_Ts]) -> tuple[ObjectRef[_T] for _T in _Ts]: ...

# backport to old python version
# def put(items: tuple[*_Ts]) -> tuple["ObjectRef[_T] for _T in _Ts"]: ...


def get(refs: tuple[*_Ts]) -> tuple[_T for ObjectRef[_T] in _Ts]: ...

We can do more things like.

from typing import Any
from typing import Callable
from typing import Generic
from typing import TypeVar
from typing import TypeVarTuple


_Callable_co = TypeVar("_Callable_co", covariant=True, bound=Callable)
_Ts = TypeVarTuple("_Ts")
_T = TypeVar("_T")


class ObjectRef(Generic[_T]): ...


class RemoteCallable(Generic[_Callable_co]):
    def __call__(self: RemoteCallable[Callable[[*_Ts], Any]], *args: *tuple[ObjectRef[_T] for _T in _Ts]): ...

For a more realistic scenario, you can refer to https://github.com/zen-xu/sunray/blob/main/sunray/_internal/callable.py

from typing.

carljm avatar carljm commented on July 24, 2024

I think this is a duplicate of #1216

from typing.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.