Skip to content

Commit

Permalink
Downgrade typing-extensions to fix conflict with spacy and `pydan…
Browse files Browse the repository at this point in the history
…tic` (#2033)

* Downgrade `typing-extensions` to fix conflict with `spacy` and `pydantic`

that results in seemingly unrelated errors like:

```python
  File "/root/.pyenv/versions/3.8.16/lib/python3.8/site-packages/spacy/schemas.py", line 250, in <module>
    class TokenPattern(BaseModel):
  File "pydantic/main.py", line 197, in pydantic.main.ModelMetaclass.__new__
  File "pydantic/fields.py", line 506, in pydantic.fields.ModelField.infer
  File "pydantic/fields.py", line 436, in pydantic.fields.ModelField.__init__
  File "pydantic/fields.py", line 552, in pydantic.fields.ModelField.prepare
  File "pydantic/fields.py", line 661, in pydantic.fields.ModelField._type_analysis
  File "pydantic/fields.py", line 668, in pydantic.fields.ModelField._type_analysis
  File "/root/.pyenv/versions/3.8.16/lib/python3.8/typing.py", line 774, in __subclasscheck__
    return issubclass(cls, self.__origin__)
TypeError: issubclass() arg 1 must be a class
```

Closes PLAT-443

* Add some comments to request linters to calm down
  • Loading branch information
meatballhat authored Oct 29, 2024
1 parent 5eb31ff commit a5759db
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ dependencies = [
"PyYAML",
"requests>=2,<3",
"structlog>=20,<25",
"typing_extensions>=4.6.0",
"typing_extensions>=4.4.0",
"uvicorn[standard]>=0.12,<1",
]

Expand Down
18 changes: 16 additions & 2 deletions python/cog/server/connection.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
import abc
import asyncio
import collections.abc
import multiprocessing
from multiprocessing.connection import Connection
from typing import Any, Optional

from typing_extensions import Buffer
# Buffer is only available in typing-extensions>=4.6.0 but should be available in stdlib
# python 3.12+. This compatibility code is nearly identical to the implementation in
# typing-extensions>=4.6.0
if hasattr(collections.abc, "Buffer"):
Buffer = collections.abc.Buffer # type: ignore
else:

class Buffer(abc.ABC): # noqa: B024
pass

Buffer.register(memoryview)
Buffer.register(bytearray)
Buffer.register(bytes)

_spawn = multiprocessing.get_context("spawn")

Expand Down Expand Up @@ -58,7 +72,7 @@ def send_bytes(
) -> None:
"""Send the bytes data from a bytes-like object"""

self._connection.send_bytes(buf, offset, size)
self._connection.send_bytes(buf, offset, size) # type: ignore

async def recv_bytes(self, maxlength: Optional[int] = None) -> bytes:
"""
Expand Down

0 comments on commit a5759db

Please sign in to comment.