explosion / spaCy

💫 Industrial-strength Natural Language Processing (NLP) in Python
https://spacy.io
MIT License
29.68k stars 4.36k forks source link

Fails on Python 3.11 #11664

Closed JelleZijlstra closed 1 year ago

JelleZijlstra commented 1 year ago

How to reproduce the behaviour

Python 3.11.0rc2 (v3.11.0rc2:ed7c3ff156, Sep 11 2022, 16:22:23) [Clang 13.0.0 (clang-1300.0.29.30)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import spacy
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/spacy/__init__.py", line 14, in <module>
    from . import pipeline  # noqa: F401
    ^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/spacy/pipeline/__init__.py", line 1, in <module>
    from .attributeruler import AttributeRuler
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/spacy/pipeline/attributeruler.py", line 6, in <module>
    from .pipe import Pipe
  File "spacy/pipeline/pipe.pyx", line 1, in init spacy.pipeline.pipe
  File "spacy/vocab.pyx", line 1, in init spacy.vocab
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/spacy/tokens/__init__.py", line 1, in <module>
    from .doc import Doc
  File "spacy/tokens/doc.pyx", line 36, in init spacy.tokens.doc
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/spacy/schemas.py", line 158, in <module>
    class TokenPatternString(BaseModel):
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pydantic/main.py", line 292, in __new__
    cls.__signature__ = ClassAttribute('__signature__', generate_model_signature(cls.__init__, fields, config))
                                                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pydantic/utils.py", line 258, in generate_model_signature
    merged_params[param_name] = Parameter(
                                ^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/inspect.py", line 2715, in __init__
    raise ValueError('{!r} is not a valid parameter name'.format(name))
ValueError: 'in' is not a valid parameter name

The class it's choking on is here: https://github.com/explosion/spaCy/blob/ceb62352bfcad49b3ad63e3e65ef12dabab645b3/spacy/schemas.py#L158 The IN field has an alias in, which is causing problems.

This behavior was changed in python/cpython#92062 (which I approved, sorry for that).

Your Environment

JelleZijlstra commented 1 year ago

This is actually fixed in pydantic 1.10.2 (pydantic/pydantic#4012), but spaCy currently requires pydantic <1.10.0. Relaxing that requirement should fix this issue. I found that PR #11635 already relaxed the requirement, so the next release that incorporates that PR should also fix this issue.

polm commented 1 year ago

Thanks for the heads-up! We are doing a little testing for 3.11 ourselves, but every bit of information like this helps.

adrianeboyd commented 1 year ago

Updates for python 3.11 for all our packages are in progress (the only remaining ones are srsly, thinc, and spacy) and should be ready by the official release date.

adrianeboyd commented 1 year ago

This should be resolved by the release of spacy v3.4.2. Please let us know if you run into any problems!

github-actions[bot] commented 1 year ago

This issue has been automatically closed because it was answered and there was no follow-up discussion.

github-actions[bot] commented 1 year ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.