Note greediness of PEP 723 reference parser
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 68/100
- Tipo de issue
- Documentación
- Claridad
- Bastante claro
- Estado de actividad
- Tranquilo
- Stack tecnológico
- python
- Área
- documentation
Línea de trabajo
Comienza con el analizador de referencia de PEP 723 y la documentación de PyPA que lo incluye, y luego reproduce el problema usando los ejemplos de REGEX y script_A/script_B del informe. Actualiza la documentación pertinente para advertir sobre la combinación codiciosa de bloques adyacentes y confirma que la advertencia describe con precisión el caso límite de TOML no válido resultante.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Issue Description
While preparing a PR for PEP 723 support in pip, I noticed that the reference parser defined by the PEP and listed in the PyPA docs will collate multiple adjacent /// TYPE blocks as a single match, even when separated by a comment line (the spec refers to it as a "content line"). This greedy collation is surprising and makes distinguishing error cases a little complicated, so I think it merits a warning in the docs if it is not possible to update the specification itself.
I believe this quirk is caused by the last + in the reference regex being greedy and matching all the way to the trailing /// instead of to the first available one. In my limited experimentation, replacing this quantifier with +? resolves the issue, producing the expected number of matches.
This shouldn't slip through anybody's code unnoticed, as the collation will produce invalid TOML (the interior /// is invalid syntax), but it is a surprising enough edge case that I thought to report it here.
click for code
import re
script_A = """
# /// script
# data (1)
# ///
#
# /// script
# data (2)
# ///
"""
script_B = """
# /// script
# data (1)
# ///
# /// script
# data (2)
# ///
"""
# These lines adapted from PEP 723's reference parser:
# https://peps.python.org/pep-0723/#reference-implementation
REGEX = r"(?m)^# /// (?P<type>[a-zA-Z0-9-]+)$\s(?P<content>(^#(| .*)$\s)+)^# ///$"
name = "script"
matches_A = list(
filter(lambda m: m.group("type") == name, re.finditer(REGEX, script_A))
)
matches_B = list(
filter(lambda m: m.group("type") == name, re.finditer(REGEX, script_B))
)
# output:
# 1
# 2
print(len(matches_A))
print(len(matches_B))
Code of Conduct
- I am aware that participants in this repository must follow the PSF Code of Conduct.
- Lenguaje dominante
- Python
- Estrellas
- 1.7k
- Forks
- 1.7k
- Merge medio
- 3 d 12 h
- PR fusionados (30 d)
- 4
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.
Más de pypa/packaging.python.org
-
component: specifications good first issue type: enhancement
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
pypa/packaging.python.org#1226 · 3 comentarios · 1 reacción ·
-
`test` vs. `tests` Abiertocomponent: guides component: tutorials type: enhancement type: task
Dificultad 2/5 1-3 horas Aptitud para principiantes 64/100
pypa/packaging.python.org#1165 · 5 comentarios ·
-
type: task
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
pypa/packaging.python.org#792 · 2 comentarios · 1 reacción ·
-
good first issue help wanted type: bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
pypa/packaging.python.org#463 · 5 comentarios ·
-
good first issue type: task
Dificultad 3/5 1-2 días Aptitud para principiantes 68/100
pypa/packaging.python.org#2037 · 2 comentarios ·
Todos los issues de pypa/packaging.python.org
Issues similares
-
documentation help wanted
Dificultad 2/5 1-3 horas Aptitud para principiantes 90/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 90/100
simonw/sqlite-utils#872 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100