Repository navigation
Closed
Labels
3.12only security fixesonly security fixes3.13only security fixesonly security fixestopic-typingtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Bug report
What happened?
import openaiTraceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.12/site-packages/openai/__init__.py", line 8, in <module>
from . import types
File "/usr/local/lib/python3.12/site-packages/openai/types/__init__.py", line 5, in <module>
from .batch import Batch as Batch
File "/usr/local/lib/python3.12/site-packages/openai/types/batch.py", line 7, in <module>
from .._models import BaseModel
File "/usr/local/lib/python3.12/site-packages/openai/_models.py", line 35, in <module>
from ._utils import (
File "/usr/local/lib/python3.12/site-packages/openai/_utils/__init__.py", line 3, in <module>
from ._utils import (
File "/usr/local/lib/python3.12/site-packages/openai/_utils/_utils.py", line 24, in <module>
from .._compat import parse_date as parse_date, parse_datetime as parse_datetime
File "/usr/local/lib/python3.12/site-packages/openai/_compat.py", line 48, in <module>
from pydantic.v1.typing import (
File "/usr/local/lib/python3.12/site-packages/pydantic/v1/__init__.py", line 7, in <module>
from .env_settings import BaseSettings
File "/usr/local/lib/python3.12/site-packages/pydantic/v1/env_settings.py", line 23, in <module>
class BaseSettings(BaseModel):
File "/usr/local/lib/python3.12/site-packages/pydantic/v1/main.py", line 178, in __new__
annotations = resolve_annotations(namespace.get('__annotations__', {}), namespace.get('__module__', None))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/pydantic/v1/typing.py", line 400, in resolve_annotations
value = _eval_type(value, base_globals, None)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^import fastapiTraceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.12/site-packages/fastapi/__init__.py", line 7, in <module>
from .applications import FastAPI as FastAPI
File "/usr/local/lib/python3.12/site-packages/fastapi/applications.py", line 16, in <module>
from fastapi import routing
File "/usr/local/lib/python3.12/site-packages/fastapi/routing.py", line 22, in <module>
from fastapi import params
File "/usr/local/lib/python3.12/site-packages/fastapi/params.py", line 5, in <module>
from fastapi.openapi.models import Example
File "/usr/local/lib/python3.12/site-packages/fastapi/openapi/models.py", line 68, in <module>
class Contact(BaseModelWithConfig):
File "/usr/local/lib/python3.12/site-packages/pydantic/_internal/_model_construction.py", line 197, in __new__
set_model_fields(cls, bases, config_wrapper, types_namespace)
File "/usr/local/lib/python3.12/site-packages/pydantic/_internal/_model_construction.py", line 474, in set_model_fields
fields, class_vars = collect_model_fields(cls, bases, config_wrapper, types_namespace, typevars_map=typevars_map)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/pydantic/_internal/_fields.py", line 131, in collect_model_fields
type_hints = get_cls_type_hints_lenient(cls, types_namespace)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/pydantic/_internal/_typing_extra.py", line 226, in get_cls_type_hints_lenient
hints[name] = eval_type_lenient(value, globalns, localns)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/pydantic/_internal/_typing_extra.py", line 238, in eval_type_lenient
return eval_type_backport(value, globalns, localns)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/pydantic/_internal/_typing_extra.py", line 255, in eval_type_backport
return typing._eval_type(value, globalns, localns)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: _eval_type() missing 1 required positional argument: 'type_params'CPython versions tested on:
3.12
Operating systems tested on:
Linux
Output from running 'python -VV' on the command line:
Python 3.12.3+ (heads/3.12-dirty:817190c, Apr 29 2024, 12:17:20) [GCC 11.4.0]
Linked PRs
Metadata
Metadata
Assignees
Labels
3.12only security fixesonly security fixes3.13only security fixesonly security fixestopic-typingtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Activity
sobolevn commentedon Apr 30, 2024
Well, this has several points.
type_params=Nonedefault in_eval_type, it won't change the code semantics. But, it will help multiple projects._eval_typewithouttype_params(or with proposedNonedefault) may just hide the bug (when working with PEP695's functions / classes) instead of being correct in all casesThis is hard :)
pythongh-118418: Use a default value for `type_params` in `typing._ev…
sobolevn commentedon Apr 30, 2024
See my sobolevn@d7483de commit that adds
Nonedefault. I am not sure that we should go for it.enefry commentedon Apr 30, 2024
🤔
Yes, I think default value will more better for exists code
sobolevn commentedon Apr 30, 2024
You closed the issue too early :)
AlexWaygood commentedon Apr 30, 2024
@enefry, I can't reproduce this issue based on the snippet you gave above:
Could you post a minimal, reproducible example please? :-)
enefry commentedon Apr 30, 2024
you may checkout commit before this commit
See my https://github.com/sobolevn/cpython/commit/d7483de262e53059671946b147c1fe62986582c7 commit that adds None default. I am not sure that we should go for it.
my library version is :
fastapi>=0.110.1
openai>=1.14.0
5 remaining items
sobolevn commentedon Apr 30, 2024
I guess this would be the compat code to workaround this problem:
PR is on its way.
AlexWaygood commentedon Apr 30, 2024
Okay, if it was "just" pydantic that was going to be broken with this, then I would have argued that they'd have plenty of time to patch their code before the release of Python 3.12.4, and that adding a default value for this parameter would just mean that pydantic would have the same bug in their use of
_eval_typethat we had prior to 1e3e7ce. But it's not just pydantic. Unfortunately,typing._eval_typehas many users outside the stdlib, much though I wish it didn't:We can't afford to break this many libraries in a patch release, so I now agree that we have no choice except to add a default value to the new parameter. After #118431 is merged, however, I would like to propose that we immediately make a Python 3.13-only change to start issuing a
DeprecationWarningifNoneis passed to this parameter. Failing to pass a value to this parameter shouldn't be encouraged: it's going to lead to incorrect behaviour if_eval_typeis called on a stringified annotation that references a PEP-695 type parameter.gh-118418: Use a default value for `type_params` in `typing._eval_typ…
pythongh-118418: Use a default value for `type_params` in `typing._ev…
terryjreedy commentedon Apr 30, 2024
Alternate suggestion: in 3.12.4 and successors, default to a private sentinel so as to detect defaulting versus explicitly passing None. If not overriden, convert it to None and issue a deprecation warning. Keep the proper signature in 3.13. There will be months for users of the private function to adjust before the latter's release. After .0b1, we can discuss making the function public, or making some other change.
[3.12] gh-118418: Use a default value for `type_params` in `typing._e…
AlexWaygood commentedon Apr 30, 2024
Unfortunately, lots of users run tests with
-Werrorin CI, so I think adding a deprecation warning in a patch release could be just as breaking as adding a new parameter without a default. So I think the earliest we can add this warning is Python 3.13.Possibly we could consider being aggressive with the deprecation period, but I think if we've conceded that this change could break quite a few libraries (even if it shouldn't), we may as well go through the standard two-cycle deprecation period for removing the default.
sobolevn commentedon Apr 30, 2024
I propose not to touch
_eval_typeanymore. Let's just provide a new public API (since this one is already public de facto). And just ship the backport intyping_extensions?pythongh-118418: Deprecate failing to pass a value to the *type_param…
AlexWaygood commentedon May 7, 2024
I don't think that's sufficient: there are already many libraries using the private API, and even if we provide a public API for them in 3.14, it will take time for them to migrate to the new public API. In the meantime, the footgun will continue to exist in the private API that they're already using.
I've put up #118695 to deprecate failing to pass a value to the new parameter. It's a pretty simple change and I think we should go ahead with it.
gh-118418: Deprecate failing to pass a value to the *type_params* par…
pythongh-118418: Use a default value for `type_params` in `typing._ev…
pythongh-118418: Deprecate failing to pass a value to the *type_param…
samuelcolvin commentedon Jun 16, 2024
Hi everyone, sorry I somehow missed the notification for this one.
@AlexWaygood thanks so much for accommodating my egregious use of a private API.
We'll get Pydantic working with 3.12.4 and 3.13 ASAP.