ParamSpec: No support for adding keyword-only argument
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've been looking through PEP 612 but I just wasn't able to find any way to implement behavior that would allow me to do this:
P = ParamSpec("P")
R = TypeVar("R")
def foo(f: Callable[P, R]) -> Callable[P, List[R]]: # Here, the parameters are actually P + optional kw-only int x = 3
def inner(*args: P.args, x: int = 3, **kwargs: P.kwargs) -> List[R]:
results = []
for _ in range(x):
ret = f(*args, **kwargs)
results.append(ret)
return results
return inner
@foo
def bar(p: int):
return p + 2
bar(5) # Acceptable
bar(5, x=8) # Should also be Acceptable
Proposed solution:
Callable[[P.args, x: int = 3, P.kwargs], List[R]]
EDIT: I didn't notice that this was already in rejected alternatives section (I didn't scroll that far), however I still think an implementation like this would be worth adding since I have already encountered the need for this twice and there's simply absolutely no way to handle it.
I'm fine with the proposed syntax suggestion of
Concatenate[("x", int), P]
Though it didn't mention anything about default values, but those could just be handled by a third value in that tuple. It would probably be a lot easier to implement than my proposed suggestion, though to be fair, at least to me, my suggestion looks a bit cleaner.
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
Empieza leyendo las alternativas rechazadas de PEP 612 y las especificaciones existentes de ParamSpec y Concatenate. Como el issue no menciona archivos de implementación ni pruebas, identifica primero los puntos de entrada relevantes de typing-spec; para darlo por terminado, debe haber una sintaxis acordada y un comportamiento definido para los parámetros keyword-only opcionales.
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
- Bastante claro
- Aptitud para principiantes
- 25/100