`parse(to=A | None)` raises "Unsupported type" below Python 3.14 while `Union[A, None]` works
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 78/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- python
- Área
- backend-api-design
Línea de trabajo
Lee _response.py y _legacy_response.py en los métodos _parse; luego comprueba cómo _utils.is_union() maneja types.UnionType. Reproduce el fallo en Python 3.12 con el fragmento de transporte simulado del issue y compara el comportamiento al analizar la respuesta sin procesar para A | None y Union[A, None]. Se considera terminado cuando ambos se analicen correctamente en versiones anteriores a Python 3.14; ejecuta las pruebas pertinentes de análisis de respuestas.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Confirm this is an issue with the Python library and not an underlying OpenAI API
- This is an issue with the Python library
Describe the bug
parse(to=...) on a raw response accepts Union[A, None] and Optional[A], but the same union written as A | None raises RuntimeError: Unsupported type on Python 3.12. On 3.14 both spellings work. I only ran 3.12 and 3.14; from the cause below, 3.10, 3.11 and 3.13 should behave like 3.12.
APIResponse._parse in _response.py and LegacyAPIResponse._parse in _legacy_response.py skip the "unsupported type" check with origin is Union. Below 3.14 the origin of A | None is types.UnionType, not typing.Union, so the check falls through to the error. The is_union() helper in _utils already handles both.
To Reproduce
- Run the snippet below on Python 3.12. It answers the request from a mock transport, so it needs no key and no network.
Union[Model, None]andOptional[Model]returnModel(id='m1').Model | Noneanddict | listraise:
RuntimeError: Unsupported type, expected __main__.Model | None to be a subclass of <class 'openai.BaseModel'>, <class 'dict'>, <class 'list'>, typing.Union, <class 'NoneType'>, <class 'str'> or <class 'httpx2.Response'>.
On Python 3.14.7 all four return a value.
Code snippets
from typing import Optional, Union
import httpx2
from openai import OpenAI
from pydantic import BaseModel
BODY = {"id": "m1", "object": "model", "created": 1, "owned_by": "x"}
client = OpenAI(
api_key="test",
base_url="http://localhost/v1",
http_client=httpx2.Client(transport=httpx2.MockTransport(lambda request: httpx2.Response(200, json=BODY))),
)
class Model(BaseModel):
id: str
for to in (Union[Model, None], Optional[Model], Model | None, dict | list):
raw = client.models.with_raw_response.retrieve("m1")
try:
print(to, "->", repr(raw.parse(to=to)))
except Exception as exc:
print(to, "->", type(exc).__name__, exc)
OS
Windows 11
Python version
Python v3.12.14 (fails), v3.14.7 (works)
Library version
openai v3.60.0 (main at f2b2399)
- Lenguaje dominante
- Python
- Estrellas
- 32.2k
- Forks
- 5.8k
- Merge medio
- 12 h 31 min
- PR fusionados (30 d)
- 101
Preparar el entorno
Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
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 openai/openai-python
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
openai/openai-python#4338 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
`DeprecationWarning` thrown when calling websockets (17.1 and later)Posiblemente ocupada @akhil9tiet la tomó hace 1 día. Abiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
openai/openai-python#4337 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
`BaseClient._prepare_url()` corrupts relative endpoint URLs when `base_url` contains query parametersPosiblemente ocupada @Rewaskc02-lang la tomó hace 2 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
openai/openai-python#4311 · 4 comentarios ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
openai/openai-python#4310 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
openai/openai-python#4309 · 1 comentario ·
Los mantenedores suelen responder en 1 día
Todos los issues de openai/openai-python
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 69/100
-
frontend testing
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
vendrabuck/HERD#1588 ·
Los mantenedores suelen responder en 1 día
-
Lessons: record the second case of L14 (security updates cover only pip)Posiblemente ocupada @vishwanathj la tomó hoy. Abiertoarea/docs no-test-needed type/docs
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
vishwanathj/ocp_lab.ai#39 · 1 comentario ·
-
enhancement good first issue
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
laaielichter/Gulliver#228 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
Los mantenedores suelen responder en 1 día