AnyStr.startswith(AnyStr) fails due to bytes not matching Buffer protocol

Abierto
#5,452 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
58/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
python, rust

Línea de trabajo

Start with the Python example in the issue and reproduce the .startswith() type error in Pyrefly, then trace how AnyStr bounds and the str and bytes method signatures are modeled. The issue names no source files or tests, so locate the relevant type-checker code and add a regression test for the example. Done means the call resolves for matching str and bytes arguments without the Buffer error.

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

Descripción

Describe the Bug
from typing import *

def func(a: AnyStr, b: AnyStr) -> bool:
    return a.startswith(b)

Python: 3.12

When creating a function as above, pyrefly fails to resolve the .startswith() call, claiming bytes doesn't satisfy Buffer.

This should resolve correctly, as AnyStr is bound to the same type for a and b, and str.startswith accepts strings and bytes.startswith accepts bytes

Sandbox Link

https://pyrefly.org/sandbox/?project=v2.I6HI1EJOoBqJVqAyNLgEWG4kwZjg6E4C5mpY2EHTth4wnRWVFJdnlmRoJAHjBjPolBUCIAIKUFcACw1gmKeXAosmYFjqxeQpA0ulVIWMkpKCYit9fZj2_KJ0_dQ8_ZT85GJ9FB36CqBUkliWmAku8FCNU8gHR3Ux0FhK4kwdEmXq-GJMHRRhQBV4IwEA

(Only applicable for extension issues) IDE Information

No response

Lenguaje dominante
Rust
Estrellas
7.2k
Forks
578
Métricas de merge de PR
Sin PR fusionados en 30 d

Preparar el entorno

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.

Más de facebook/pyrefly

Todos los issues de facebook/pyrefly

Issues similares

Más issues de Rust

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.