spaCy/spacy
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
..
cli Fix --require-parent default 2024-09-29 15:50:31 +02:00
displacy Fix displacy span stacking (#13068) 2023-11-02 12:02:18 +01:00
kb Update __all__ fields (#13063) 2023-10-16 10:17:47 +02:00
lang Python 3.13 support (#13823) 2025-05-22 13:47:21 +02:00
matcher Python 3.13 support (#13823) 2025-05-22 13:47:21 +02:00
ml Python 3.13 support (#13823) 2025-05-22 13:47:21 +02:00
pipeline Python 3.13 support (#13823) 2025-05-22 13:47:21 +02:00
tests Python 3.13 support (#13823) 2025-05-22 13:47:21 +02:00
tokens Python 3.13 support (#13823) 2025-05-22 13:47:21 +02:00
training Python 3.13 support (#13823) 2025-05-22 13:47:21 +02:00
__init__.pxd * Seems to be working after refactor. Need to wire up more POS tag features, and wire up save/load of POS tags. 2014-10-24 02:23:42 +11:00
__init__.py Python 3.13 support (#13823) 2025-05-22 13:47:21 +02:00
__main__.py Tidy up 2020-06-22 00:45:40 +02:00
about.py Update version 2025-05-18 12:18:38 +02:00
attrs.pxd ci: add cython linter (#12694) 2023-07-19 12:03:31 +02:00
attrs.pyx Add profile=False to currently unprofiled cython 2023-09-28 17:09:41 +02:00
compat.py Configure isort to use the Black profile, recursively isort the spacy module (#12721) 2023-06-14 17:48:41 +02:00
default_config_pretraining.cfg Add new parameter for saving every n epoch in pretraining (#8912) 2021-08-12 11:14:48 +02:00
default_config.cfg Support registered vectors (#12492) 2023-08-01 15:46:08 +02:00
errors.py Make Language.pipe workers exit cleanly (#13321) 2024-02-12 14:39:38 +01:00
glossary.py Configure isort to use the Black profile, recursively isort the spacy module (#12721) 2023-06-14 17:48:41 +02:00
language.py Python 3.13 support (#13823) 2025-05-22 13:47:21 +02:00
lexeme.pxd Python 3.13 support (#13823) 2025-05-22 13:47:21 +02:00
lexeme.pyi Configure isort to use the Black profile, recursively isort the spacy module (#12721) 2023-06-14 17:48:41 +02:00
lexeme.pyx Python 3.13 support (#13823) 2025-05-22 13:47:21 +02:00
lookups.py Configure isort to use the Black profile, recursively isort the spacy module (#12721) 2023-06-14 17:48:41 +02:00
morphology.pxd ci: add cython linter (#12694) 2023-07-19 12:03:31 +02:00
morphology.pyx Fix allocation of non-transient strings in StringStore (#13713) 2024-12-11 13:06:53 +01:00
parts_of_speech.pxd ci: add cython linter (#12694) 2023-07-19 12:03:31 +02:00
parts_of_speech.pyx Python 3.13 support (#13823) 2025-05-22 13:47:21 +02:00
pipe_analysis.py Configure isort to use the Black profile, recursively isort the spacy module (#12721) 2023-06-14 17:48:41 +02:00
py.typed Add py.typed 2021-03-16 09:48:31 +01:00
registrations.py Python 3.13 support (#13823) 2025-05-22 13:47:21 +02:00
schemas.py Merge remote-tracking branch 'upstream/master' into chore/update-develop-from-master-v3.7-1 2023-09-28 15:09:06 +02:00
scorer.py Update for numpy 2.0 deprecations (#13103) 2023-11-06 08:47:53 +01:00
strings.pxd Fix memory zones 2024-09-09 13:49:41 +02:00
strings.pyi Configure isort to use the Black profile, recursively isort the spacy module (#12721) 2023-06-14 17:48:41 +02:00
strings.pyx Fix allocation of non-transient strings in StringStore (#13713) 2024-12-11 13:06:53 +01:00
structs.pxd ci: add cython linter (#12694) 2023-07-19 12:03:31 +02:00
symbols.pxd ci: add cython linter (#12694) 2023-07-19 12:03:31 +02:00
symbols.pyx Python 3.13 support (#13823) 2025-05-22 13:47:21 +02:00
tokenizer.pxd Support 'memory zones' for user memory management (#13621) 2024-09-09 11:19:39 +02:00
tokenizer.pyx Python 3.13 support (#13823) 2025-05-22 13:47:21 +02:00
ty.py Configure isort to use the Black profile, recursively isort the spacy module (#12721) 2023-06-14 17:48:41 +02:00
typedefs.pxd Configure isort to use the Black profile, recursively isort the spacy module (#12721) 2023-06-14 17:48:41 +02:00
typedefs.pyx Add profile=False to currently unprofiled cython 2023-09-28 17:09:41 +02:00
util.py Python 3.13 support (#13823) 2025-05-22 13:47:21 +02:00
vectors.pyx Python 3.13 support (#13823) 2025-05-22 13:47:21 +02:00
vocab.pxd Support 'memory zones' for user memory management (#13621) 2024-09-09 11:19:39 +02:00
vocab.pyi Support 'memory zones' for user memory management (#13621) 2024-09-09 11:19:39 +02:00
vocab.pyx Fix memory zones 2024-09-09 13:49:41 +02:00