spaCy/spacy/tokens
Matthew Honnibal 5bebbf7550
Python 3.13 support (#13823)
In order to support Python 3.13, we had to migrate to Cython 3.0. This caused some tricky interaction with our Pydantic usage, because Cython 3 uses the from __future__ import annotations semantics, which causes type annotations to be saved as strings.

The end result is that we can't have Language.factory decorated functions in Cython modules anymore, as the Language.factory decorator expects to inspect the signature of the functions and build a Pydantic model. If the function is implemented in Cython, an error is raised because the type is not resolved.

To address this I've moved the factory functions into a new module, spacy.pipeline.factories. I've added __getattr__ importlib hooks to the previous locations, in case anyone was importing these functions directly. The change should have no backwards compatibility implications.

Along the way I've also refactored the registration of functions for the config. Previously these ran as import-time side-effects, using the registry decorator. I've created instead a new module spacy.registrations. When the registry is accessed it calls a function ensure_populated(), which cases the registrations to occur.

I've made a similar change to the Language.factory registrations in the new spacy.pipeline.factories module.

I want to remove these import-time side-effects so that we can speed up the loading time of the library, which can be especially painful on the CLI. I also find that I'm often working to track down the implementations of functions referenced by strings in the config. Having the registrations all happen in one place will make this easier.

With these changes I've fortunately avoided the need to migrate to Pydantic v2 properly --- we're still using the v1 compatibility shim. We might not be able to hold out forever though: Pydantic (reasonably) aren't actively supporting the v1 shims. I put a lot of work into v2 migration when investigating the 3.13 support, and it's definitely challenging. In any case, it's a relief that we don't have to do the v2 migration at the same time as the Cython 3.0/Python 3.13 support.
2025-05-22 13:47:21 +02:00
..
__init__.pxd * Break up tokens.pyx into tokens/doc.pyx, tokens/token.pyx, tokens/spans.pyx 2015-07-13 20:20:58 +02:00
__init__.py Update __all__ fields (#13063) 2023-10-16 10:17:47 +02:00
_dict_proxies.py Configure isort to use the Black profile, recursively isort the spacy module (#12721) 2023-06-14 17:48:41 +02:00
_retokenize.pyi Configure isort to use the Black profile, recursively isort the spacy module (#12721) 2023-06-14 17:48:41 +02:00
_retokenize.pyx Remove profile=True from currently profiled cython 2023-09-28 17:09:41 +02:00
_serialize.py Configure isort to use the Black profile, recursively isort the spacy module (#12721) 2023-06-14 17:48:41 +02:00
doc.pxd Python 3.13 support (#13823) 2025-05-22 13:47:21 +02:00
doc.pyi Type documentation fixes for Doc (#13187) 2023-12-18 09:00:47 +01:00
doc.pyx Python 3.13 support (#13823) 2025-05-22 13:47:21 +02:00
graph.pxd Configure isort to use the Black profile, recursively isort the spacy module (#12721) 2023-06-14 17:48:41 +02:00
graph.pyx Add profile=False to currently unprofiled cython 2023-09-28 17:09:41 +02:00
morphanalysis.pxd Configure isort to use the Black profile, recursively isort the spacy module (#12721) 2023-06-14 17:48:41 +02:00
morphanalysis.pyi Configure isort to use the Black profile, recursively isort the spacy module (#12721) 2023-06-14 17:48:41 +02:00
morphanalysis.pyx Add profile=False to currently unprofiled cython 2023-09-28 17:09:41 +02:00
span_group.pxd Configure isort to use the Black profile, recursively isort the spacy module (#12721) 2023-06-14 17:48:41 +02:00
span_group.pyi feat: add type hinting on SpanGroup.__iter__ (#12642) 2023-05-17 14:20:00 +02:00
span_group.pyx Add profile=False to currently unprofiled cython 2023-09-28 17:09:41 +02:00
span.pxd Configure isort to use the Black profile, recursively isort the spacy module (#12721) 2023-06-14 17:48:41 +02:00
span.pyi feat: add comparison operators in span.pyi (#12652) 2023-05-23 08:50:37 +02:00
span.pyx Convert properties to decorator syntax (#13390) 2024-04-16 11:51:14 +02:00
token.pxd Python 3.13 support (#13823) 2025-05-22 13:47:21 +02:00
token.pyi Support Any comparisons for Token and Span (#13058) 2023-10-12 11:53:33 +02:00
token.pyx Convert properties to decorator syntax (#13390) 2024-04-16 11:51:14 +02:00
underscore.py Configure isort to use the Black profile, recursively isort the spacy module (#12721) 2023-06-14 17:48:41 +02:00