Bug 2256753 - python-pydantic fails to build with Python 3.13: TypeError: typing.Annotated cannot be used with issubclass()
Summary: python-pydantic fails to build with Python 3.13: TypeError: typing.Annotated ...
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Fedora
Classification: Fedora
Component: python-pydantic
Version: 40
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Maxwell G
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
: 2291854 (view as bug list)
Depends On: 2259626
Blocks: F41FTBFS F41FailsToInstall 2238165 PYTHON3.13 2291499 2291517 2291520 2291530 2291559 2291585 2291641 2291697 2291774 2291807 2291813 2291852 2291854 2291855 2291856 2291885 2291887 2291890 2291891 2291914 2291966 2291977 2292905
TreeView+ depends on / blocked
 
Reported: 2024-01-04 11:12 UTC by Karolina Surma
Modified: 2024-06-29 15:11 UTC (History)
7 users (show)

Fixed In Version: python-pydantic-2.8.0~b1-1.fc41
Clone Of:
Environment:
Last Closed: 2024-06-29 15:11:28 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Github PyO3 pyo3 issues 3555 0 None open How to keep users safe regarding alpha Pythons? 2024-01-04 14:45:34 UTC
Github pydantic pydantic issues 7942 0 None closed TypeError raised when using generics in python 3.13 2024-01-04 14:45:34 UTC
Github pydantic pydantic issues 9668 0 None open Support Python 3.13 2024-06-15 20:47:19 UTC

Description Karolina Surma 2024-01-04 11:12:37 UTC
python-pydantic fails to build with Python 3.13.0a2.

+ /usr/bin/pytest --ignore=tests/test_docs.py --ignore=tests/benchmarks
============================= test session starts ==============================
platform linux -- Python 3.13.0a2, pytest-7.4.3, pluggy-1.3.0
rootdir: /builddir/build/BUILD/pydantic-2.5.3
configfile: pyproject.toml
testpaths: tests
plugins: mock-3.12.0
collected 4217 items / 1 error

==================================== ERRORS ====================================
_________________ ERROR collecting tests/test_type_adapter.py __________________
pydantic/_internal/_fields.py:192: in collect_model_fields
    raise AttributeError
E   AttributeError

During handling of the above exception, another exception occurred:
/usr/lib/python3.13/site-packages/_pytest/runner.py:341: in from_call
    result: Optional[TResult] = func()
/usr/lib/python3.13/site-packages/_pytest/runner.py:372: in <lambda>
    call = CallInfo.from_call(lambda: list(collector.collect()), "collect")
/usr/lib/python3.13/site-packages/_pytest/python.py:531: in collect
    self._inject_setup_module_fixture()
/usr/lib/python3.13/site-packages/_pytest/python.py:545: in _inject_setup_module_fixture
    self.obj, ("setUpModule", "setup_module")
/usr/lib/python3.13/site-packages/_pytest/python.py:310: in obj
    self._obj = obj = self._getobj()
/usr/lib/python3.13/site-packages/_pytest/python.py:528: in _getobj
    return self._importtestmodule()
/usr/lib/python3.13/site-packages/_pytest/python.py:617: in _importtestmodule
    mod = import_path(self.path, mode=importmode, root=self.config.rootpath)
/usr/lib/python3.13/site-packages/_pytest/pathlib.py:567: in import_path
    importlib.import_module(module_name)
/usr/lib64/python3.13/importlib/__init__.py:88: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
<frozen importlib._bootstrap>:1381: in _gcd_import
    ???
<frozen importlib._bootstrap>:1354: in _find_and_load
    ???
<frozen importlib._bootstrap>:1325: in _find_and_load_unlocked
    ???
<frozen importlib._bootstrap>:929: in _load_unlocked
    ???
/usr/lib/python3.13/site-packages/_pytest/assertion/rewrite.py:186: in exec_module
    exec(co, module.__dict__)
tests/test_type_adapter.py:26: in <module>
    class GenericPydanticModel(BaseModel, Generic[T]):
pydantic/_internal/_model_construction.py:181: in __new__
    set_model_fields(cls, bases, config_wrapper, types_namespace)
pydantic/_internal/_model_construction.py:426: in set_model_fields
    fields, class_vars = collect_model_fields(cls, bases, config_wrapper, types_namespace, typevars_map=typevars_map)
pydantic/_internal/_fields.py:195: in collect_model_fields
    field_info = FieldInfo.from_annotation(ann_type)
pydantic/fields.py:287: in from_annotation
    if _typing_extra.is_annotated(annotation):
pydantic/_internal/_typing_extra.py:103: in is_annotated
    return origin is not None and lenient_issubclass(origin, Annotated)
pydantic/_internal/_utils.py:75: in lenient_issubclass
    return isinstance(cls, type) and issubclass(cls, class_or_tuple)
/usr/lib64/python3.13/typing.py:486: in __subclasscheck__
    raise TypeError(f"{self} cannot be used with issubclass()")
E   TypeError: typing.Annotated cannot be used with issubclass()
=========================== short test summary info ============================
ERROR tests/test_type_adapter.py - TypeError: typing.Annotated cannot be used...
!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!
=============================== 1 error in 4.87s ===============================

https://docs.python.org/3.13/whatsnew/3.13.html

For the build logs, see:
https://copr-be.cloud.fedoraproject.org/results/@python/python3.13/fedora-rawhide-x86_64/06849357-python-pydantic/

For all our attempts to build python-pydantic with Python 3.13, see:
https://copr.fedorainfracloud.org/coprs/g/python/python3.13/package/python-pydantic/

Testing and mass rebuild of packages is happening in copr.
You can follow these instructions to test locally in mock if your package builds with Python 3.13:
https://copr.fedorainfracloud.org/coprs/g/python/python3.13/

Let us know here if you have any questions.

Python 3.13 is planned to be included in Fedora 41.
To make that update smoother, we're building Fedora packages with all pre-releases of Python 3.13.
A build failure prevents us from testing all dependent packages (transitive [Build]Requires),
so if this package is required a lot, it's important for us to get it fixed soon.

We'd appreciate help from the people who know this package best,
but if you don't want to work on this now, let us know so we can try to work around it on our side.

Comment 1 Ben Beasley 2024-01-04 14:45:34 UTC
The traceback matches a similar issue that was reported upstream a few months ago in https://github.com/pydantic/pydantic/issues/7942. The conclusion was that the problem is that PyO3 (https://github.com/PyO3/pyo3, https://src.fedoraproject.org/rpms/rust-pyo3/), which is used for the Rust bindings in pydantic-core, doesn’t support alpha versions of Python (and relies on version-specific implementation details of the Python interpreter).

This resulted in an issue filed with PyO3 upstream, https://github.com/PyO3/pyo3/issues/3555, which has further discussion. It looks like PyO3 upstream plans to add an explicit maximum Python version, which makes sense since FFI discrepancies could result in undefined behavior and/or unsoundness, but also means we won’t be able to easily test any Python+Rust packages that use PyO3 until PyO3 advertises support for the new Python, which will take *at least* until the Python beta period.

Comment 2 Fedora Update System 2024-01-05 10:35:07 UTC
FEDORA-2024-7b94f60ebb has been submitted as an update to Fedora 40. https://bodhi.fedoraproject.org/updates/FEDORA-2024-7b94f60ebb

Comment 3 Fedora Update System 2024-01-05 10:36:22 UTC
FEDORA-2024-7b94f60ebb has been pushed to the Fedora 40 stable repository.
If problem still persists, please make note of it in this bug report.

Comment 4 Ben Beasley 2024-01-05 12:14:06 UTC
Reopening. An update had the wrong bug number associated.

Comment 5 Aoife Moloney 2024-02-15 23:08:47 UTC
This bug appears to have been reported against 'rawhide' during the Fedora Linux 40 development cycle.
Changing version to 40.

Comment 6 Karolina Surma 2024-05-28 09:15:57 UTC
With the pydantic-core fixed build, the build of pydantic fails on import error. See: https://download.copr.fedorainfracloud.org/results/@python/python3.13/fedora-rawhide-x86_64/07497940-python-pydantic/builder-live.log.gz

Check import: pydantic.root_model
Traceback (most recent call last):
  File "/usr/lib/rpm/redhat/import_all_modules.py", line 171, in <module>
    main()
    ~~~~^^
  File "/usr/lib/rpm/redhat/import_all_modules.py", line 167, in main
    import_modules(modules)
    ~~~~~~~~~~~~~~^^^^^^^^^
  File "/usr/lib/rpm/redhat/import_all_modules.py", line 100, in import_modules
    importlib.import_module(module)
    ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^
  File "/usr/lib64/python3.13/importlib/__init__.py", line 88, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 1021, in exec_module
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "/builddir/build/BUILDROOT/python-pydantic-2.7.1-1.fc41.x86_64/usr/lib/python3.13/site-packages/pydantic/root_model.py", line 36, in <module>
    class RootModel(BaseModel, typing.Generic[RootModelRootType], metaclass=_RootModelMetaclass):
    ...<118 lines>...
            yield 'root', self.root
  File "/builddir/build/BUILDROOT/python-pydantic-2.7.1-1.fc41.x86_64/usr/lib/python3.13/site-packages/pydantic/_internal/_model_construction.py", line 202, in __new__
    complete_model_class(
    ~~~~~~~~~~~~~~~~~~~~^
        cls,
        ^^^^
    ...<4 lines>...
        create_model_module=_create_model_module,
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/builddir/build/BUILDROOT/python-pydantic-2.7.1-1.fc41.x86_64/usr/lib/python3.13/site-packages/pydantic/_internal/_model_construction.py", line 539, in complete_model_class
    schema = cls.__get_pydantic_core_schema__(cls, handler)
  File "/builddir/build/BUILDROOT/python-pydantic-2.7.1-1.fc41.x86_64/usr/lib/python3.13/site-packages/pydantic/main.py", line 626, in __get_pydantic_core_schema__
    return handler(source)
  File "/builddir/build/BUILDROOT/python-pydantic-2.7.1-1.fc41.x86_64/usr/lib/python3.13/site-packages/pydantic/_internal/_schema_generation_shared.py", line 82, in __call__
    schema = self._handler(source_type)
  File "/builddir/build/BUILDROOT/python-pydantic-2.7.1-1.fc41.x86_64/usr/lib/python3.13/site-packages/pydantic/_internal/_generate_schema.py", line 502, in generate_schema
    schema = self._generate_schema_inner(obj)
  File "/builddir/build/BUILDROOT/python-pydantic-2.7.1-1.fc41.x86_64/usr/lib/python3.13/site-packages/pydantic/_internal/_generate_schema.py", line 753, in _generate_schema_inner
    return self._model_schema(obj)
           ~~~~~~~~~~~~~~~~~~^^^^^
  File "/builddir/build/BUILDROOT/python-pydantic-2.7.1-1.fc41.x86_64/usr/lib/python3.13/site-packages/pydantic/_internal/_generate_schema.py", line 565, in _model_schema
    root_field = self._common_field_schema('root', fields['root'], decorators)
  File "/builddir/build/BUILDROOT/python-pydantic-2.7.1-1.fc41.x86_64/usr/lib/python3.13/site-packages/pydantic/_internal/_generate_schema.py", line 1081, in _common_field_schema
    schema = self._apply_annotations(
        source_type,
        annotations,
    )
  File "/builddir/build/BUILDROOT/python-pydantic-2.7.1-1.fc41.x86_64/usr/lib/python3.13/site-packages/pydantic/_internal/_generate_schema.py", line 1820, in _apply_annotations
    schema = get_inner_schema(source_type)
  File "/builddir/build/BUILDROOT/python-pydantic-2.7.1-1.fc41.x86_64/usr/lib/python3.13/site-packages/pydantic/_internal/_schema_generation_shared.py", line 82, in __call__
    schema = self._handler(source_type)
  File "/builddir/build/BUILDROOT/python-pydantic-2.7.1-1.fc41.x86_64/usr/lib/python3.13/site-packages/pydantic/_internal/_generate_schema.py", line 1801, in inner_handler
    schema = self._generate_schema_inner(obj)
  File "/builddir/build/BUILDROOT/python-pydantic-2.7.1-1.fc41.x86_64/usr/lib/python3.13/site-packages/pydantic/_internal/_generate_schema.py", line 758, in _generate_schema_inner
    return self.match_type(obj)
           ~~~~~~~~~~~~~~~^^^^^
  File "/builddir/build/BUILDROOT/python-pydantic-2.7.1-1.fc41.x86_64/usr/lib/python3.13/site-packages/pydantic/_internal/_generate_schema.py", line 817, in match_type
    return self._unsubstituted_typevar_schema(obj)
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^
  File "/builddir/build/BUILDROOT/python-pydantic-2.7.1-1.fc41.x86_64/usr/lib/python3.13/site-packages/pydantic/_internal/_generate_schema.py", line 1667, in _unsubstituted_typevar_schema
    return self.generate_schema(default)
           ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
  File "/builddir/build/BUILDROOT/python-pydantic-2.7.1-1.fc41.x86_64/usr/lib/python3.13/site-packages/pydantic/_internal/_generate_schema.py", line 502, in generate_schema
    schema = self._generate_schema_inner(obj)
  File "/builddir/build/BUILDROOT/python-pydantic-2.7.1-1.fc41.x86_64/usr/lib/python3.13/site-packages/pydantic/_internal/_generate_schema.py", line 758, in _generate_schema_inner
    return self.match_type(obj)
           ~~~~~~~~~~~~~~~^^^^^
  File "/builddir/build/BUILDROOT/python-pydantic-2.7.1-1.fc41.x86_64/usr/lib/python3.13/site-packages/pydantic/_internal/_generate_schema.py", line 844, in match_type
    return self._unknown_type_schema(obj)
           ~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^
  File "/builddir/build/BUILDROOT/python-pydantic-2.7.1-1.fc41.x86_64/usr/lib/python3.13/site-packages/pydantic/_internal/_generate_schema.py", line 405, in _unknown_type_schema
    raise PydanticSchemaGenerationError(
    ...<7 lines>...
    )
pydantic.errors.PydanticSchemaGenerationError: Unable to generate pydantic-core schema for typing.NoDefault. Set `arbitrary_types_allowed=True` in the model_config to ignore this error or implement `__get_pydantic_core_schema__` on your type to fully support it.

If you got this error by calling handler(<some type>) within `__get_pydantic_core_schema__` then you likely need to call `handler.generate_schema(<some type>)` since we do not call `__get_pydantic_core_schema__` on `<some type>` otherwise to avoid infinite recursion.

For further information visit https://errors.pydantic.dev/2.7/u/schema-for-unknown-type

Comment 7 Karolina Surma 2024-05-28 09:22:14 UTC
When attempting to skip import tests and run the test suite, it errors with 15 times "DeprecationWarning: Failing to pass a value to the 'type_params' parameter of 'typing._eval_type' is deprecated, as it leads to incorrect behaviour when calling typing._eval_type on a stringified annotation that references a PEP 695 type parameter. It will be disallowed in Python 3.15."

_________________ ERROR collecting tests/test_construction.py __________________
/usr/lib/python3.13/site-packages/_pytest/runner.py:341: in from_call
    result: Optional[TResult] = func()
/usr/lib/python3.13/site-packages/_pytest/runner.py:372: in <lambda>
    call = CallInfo.from_call(lambda: list(collector.collect()), "collect")
/usr/lib/python3.13/site-packages/_pytest/python.py:531: in collect
    self._inject_setup_module_fixture()
/usr/lib/python3.13/site-packages/_pytest/python.py:545: in _inject_setup_module_fixture
    self.obj, ("setUpModule", "setup_module")
/usr/lib/python3.13/site-packages/_pytest/python.py:310: in obj
    self._obj = obj = self._getobj()
/usr/lib/python3.13/site-packages/_pytest/python.py:528: in _getobj
    return self._importtestmodule()
/usr/lib/python3.13/site-packages/_pytest/python.py:617: in _importtestmodule
    mod = import_path(self.path, mode=importmode, root=self.config.rootpath)
/usr/lib/python3.13/site-packages/_pytest/pathlib.py:567: in import_path
    importlib.import_module(module_name)
/usr/lib64/python3.13/importlib/__init__.py:88: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
<frozen importlib._bootstrap>:1387: in _gcd_import
    ???
<frozen importlib._bootstrap>:1360: in _find_and_load
    ???
<frozen importlib._bootstrap>:1331: in _find_and_load_unlocked
    ???
<frozen importlib._bootstrap>:935: in _load_unlocked
    ???
/usr/lib/python3.13/site-packages/_pytest/assertion/rewrite.py:186: in exec_module
    exec(co, module.__dict__)
tests/test_construction.py:10: in <module>
    class Model(BaseModel):
pydantic/_internal/_model_construction.py:197: in __new__
    set_model_fields(cls, bases, config_wrapper, types_namespace)
pydantic/_internal/_model_construction.py:474: in set_model_fields
    fields, class_vars = collect_model_fields(cls, bases, config_wrapper, types_namespace, typevars_map=typevars_map)
pydantic/_internal/_fields.py:131: in collect_model_fields
    type_hints = get_cls_type_hints_lenient(cls, types_namespace)
pydantic/_internal/_typing_extra.py:226: in get_cls_type_hints_lenient
    hints[name] = eval_type_lenient(value, globalns, localns)
pydantic/_internal/_typing_extra.py:238: in eval_type_lenient
    return eval_type_backport(value, globalns, localns)
pydantic/_internal/_typing_extra.py:254: in eval_type_backport
    return typing._eval_type(  # type: ignore
/usr/lib64/python3.13/typing.py:471: in _eval_type
    _deprecation_warning_for_no_type_params_passed("typing._eval_type")
/usr/lib64/python3.13/typing.py:451: in _deprecation_warning_for_no_type_params_passed
    warnings.warn(depr_message, category=DeprecationWarning, stacklevel=3)
E   DeprecationWarning: Failing to pass a value to the 'type_params' parameter of 'typing._eval_type' is deprecated, as it leads to incorrect behaviour when calling typing._eval_type on a stringified annotation that references a PEP 695 type parameter. It will be disallowed in Python 3.15.

Comment 8 Ben Beasley 2024-05-30 19:33:40 UTC
(In reply to Karolina Surma from comment #7)
> When attempting to skip import tests and run the test suite, it errors with
> 15 times "DeprecationWarning: Failing to pass a value to the 'type_params'
> parameter of 'typing._eval_type' is deprecated, as it leads to incorrect
> behaviour when calling typing._eval_type on a stringified annotation that
> references a PEP 695 type parameter. It will be disallowed in Python 3.15."

I just proposed ignoring that as part of https://src.fedoraproject.org/rpms/python-pydantic/pull-request/25. When I do that, and do a local Python 3.13 mock build with https://src.fedoraproject.org/rpms/python-pydantic-core/pull-request/9 and https://src.fedoraproject.org/rpms/python-pydantic/pull-request/25, I’m left with the original error:

==================================== ERRORS ====================================
_________________ ERROR collecting tests/test_type_adapter.py __________________
pydantic/_internal/_fields.py:209: in collect_model_fields
    raise AttributeError
E   AttributeError

[...]

/usr/lib64/python3.13/typing.py:572: in __subclasscheck__
    raise TypeError(f"{self} cannot be used with issubclass()")
E   TypeError: typing.Annotated cannot be used with issubclass()
=========================== short test summary info ============================
ERROR tests/test_type_adapter.py - TypeError: typing.Annotated cannot be used...
!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!
=============================== 1 error in 2.76s ===============================

Comment 9 Karolina Surma 2024-06-12 15:05:50 UTC
*** Bug 2291854 has been marked as a duplicate of this bug. ***

Comment 10 Fedora Fails To Install 2024-06-19 19:58:07 UTC
Hello,

Please note that this comment was generated automatically by https://pagure.io/releng/blob/main/f/scripts/ftbfs-fti/follow-policy.py
If you feel that this output has mistakes, please open an issue at https://pagure.io/releng/

This package fails to install and maintainers are advised to take one of the following actions:

 - Fix this bug and close this bugzilla once the update makes it to the repository.
   (The same script that posted this comment will eventually close this bugzilla
   when the fixed package reaches the repository, so you don't have to worry about it.)

or

 - Move this bug to ASSIGNED if you plan on fixing this, but simply haven't done so yet.

or

 - Orphan the package if you no longer plan to maintain it.


If you do not take one of these actions, the process at https://docs.fedoraproject.org/en-US/fesco/Fails_to_build_from_source_Fails_to_install/#_package_removal_for_long_standing_ftbfs_and_fti_bugs will continue.
This package may be orphaned in 7+ weeks.
This is the first reminder (step 3) from the policy.

Don't hesitate to ask for help on https://lists.fedoraproject.org/archives/list/devel@lists.fedoraproject.org/ if you are unsure how to fix this bug.

Comment 11 Ben Beasley 2024-06-20 01:36:05 UTC
Waiting for upstream; expecting a release near the end of the month per https://github.com/pydantic/pydantic/issues/9668.

Comment 12 Fedora Update System 2024-06-29 15:07:41 UTC
FEDORA-2024-31864cee47 (python-pydantic-2.8.0~b1-1.fc41, python-pydantic-core-2.20.0-1.fc41, and 1 more) has been submitted as an update to Fedora 41.
https://bodhi.fedoraproject.org/updates/FEDORA-2024-31864cee47

Comment 13 Fedora Update System 2024-06-29 15:11:28 UTC
FEDORA-2024-31864cee47 (python-pydantic-2.8.0~b1-1.fc41, python-pydantic-core-2.20.0-1.fc41, and 1 more) has been pushed to the Fedora 41 stable repository.
If problem still persists, please make note of it in this bug report.


Note You need to log in before you can comment on or make changes to this bug.