python / python/typing

[spec] clarification or change of "`partial\n` in a `py.typed` file"

Abierto
#2,113 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

topic: typing spec
Lenguaje dominante
Python
Estrellas
1.8k
Forks
302
Merge medio
23 h
PR fusionados (30 d)
8

Descripción

Reading through https://typing.python.org/en/latest/spec/distributing.html#partial-stub-packages today for unrelated purposes, it struck me that the occurrences of partial\n are ambiguous because it could be interpreted as requiring literally a backslash and an n. Furthermore, assuming \n is actually not to be taken literally (which is reasonable given that other places in the spec use glob stars anyway, although never in something you actually type into a file) it's ambiguous what happens if you use CRLF or CR as line terminators in your file. This also seems to rule out a file that just contains partial and then ends, without a newline character (you're not "supposed to" do this, but it happens).

To keep exactly the current behavior, I think this verbiage should be tweaked to "partial, followed by a newline". Perhaps the linefeed and carriage return characters could be mentioned explicitly, or a mention can be made of universal newlines.

However, I am not sure if the current behavior is actually important to specify, and I think other possibilities make more sense. Other possibilities include "partial on a line by itself", "partial surrounded by any amount of whitespace", and just "partial". "As the sole content of the file" may be added if desired.

A brief survey suggests that:

  • mypy does fscache.read(stub_typed_file).decode().strip() == "partial", which is not quite the same as the specified check
  • pyright does (pyTypedContents.match(/partial\n/) || pyTypedContents.match(/partial\r\n/)), which is certainly a reasonable interpretation of the current spec, especially if you assume that no one ever uses only-CR newlines
  • ty does to_ascii_lowercase().contains("partial") to be deliberately permissive, as explained in a comment

There is a reasonably long discussion about this topic over at https://discuss.python.org/t/pep-561-clarification-regarding-n/32875, but I didn't find it very enlightening.

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Empieza leyendo la sección sobre paquetes de stubs parciales en distributing.html y, después, compara las comprobaciones enlazadas de mypy, pyright y ty, así como el hilo referenciado de discuss.python.org. Se considera terminado cuando se haya acordado la regla de coincidencia prevista y se haya actualizado la especificación para expresarla sin ambigüedades, incluido el comportamiento de los saltos de línea y del final del archivo.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
python
Área
documentation
Tipo de issue
Documentación
Dificultad
5/5
Tiempo estimado
Más de una semana
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
35/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.