Type interference: `ProtocolOf`?
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Python
- Estrellas
- 1.8k
- Forks
- 302
- Merge medio
- 23 h
- PR fusionados (30 d)
- 8
Descripción
I'm looking the way to interfere existing types explicitly, like typeof / keyof in Typescript
I have 2 use cases:
- existing function definition ->
Callable[...] - dataclass
__init__signature / protocol
I think it should look like:
from typing import ProtocolOf
def foo(a: int, b: float) -> float:
return a * b
FooProtocol = ProtocolOf[foo]
Should be equal to:
class FooProtocol(Protocol):
def __call__(a: int, b: float) -> float: ...
Or dataclasses:
from dataclasses import dataclass
from typing import ProtocolOf
@dataclass()
class Foo:
a: int
b: float
Here I'm not sure which way is better
# way 1:
FooProtocol = ProtocolOf[Foo]
Should be equal to:
class FooProtocol(Protocol):
def __call__(a: int, b: float) -> Foo: ...
# way 2:
FooInitProtocol = ProtocolOf["Foo.__init__"]
Should be equal to:
class FooInitProtocol(Protocol):
def __call__(a: int, b: float) -> None: ...
Callable / Protocol to ParamSpec / Returning to use in typing
I see typing.get_args but it doesn't looks suitable for typing. Also
from collections.abc import Callable
from typing import get_args
FooSignature = Callable[[int, float], float]
get_args(FooSignature) # == [[int, float], float]
Instead of that it should be way to define FooParamSpec / FooReturning
Bonus
there are no way to convert TypedDict to ParamSpec.kwargs
UPD: is't bound to typing.Unpack
Guía de contribución
No hay ninguna guía de contribución indexada para este repositorio
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza revisando los ejemplos del issue y las APIs typing.get_args, Callable, Protocol, ParamSpec, TypedDict, Unpack y dataclasses a las que se hace referencia. El issue no menciona archivos del repositorio ni pruebas; para darlo por terminado sería necesario contar primero con un diseño concreto y acordado para la funcionalidad propuesta de typing, antes de poder definir el alcance de la implementación.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- tooling
- Tipo de issue
- Nueva funcionalidad
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Estado de actividad
- Estancado
- Claridad
- Necesita aclaración
- Aptitud para principiantes
- 25/100