developmentseed / geojson-pydantic

Pydantic data models for the GeoJSON spec
https://developmentseed.org/geojson-pydantic/
MIT License
229 stars 35 forks source link

Issue using typing-extensions > 4.5.0 #162

Open ondrej-ivanko opened 2 months ago

ondrej-ivanko commented 2 months ago

Hi,

when I was trying you package with one of the newest versions of FastaAPI which depends on typing-extension >=4.8.0, I ran into a typing error in your code. It applies I believe only to python version less than 3.10. There were changes to Literal which you're using in cases of some of your pydantic Models

I have to use python 3.9 along with Pydantic 1.10.x for dependency purposes. Our company cannot raise the versions of some libraries without proper testing. Is it possible on you side to create new 0.6.x patch version, which uses typing which would work on Python 3.9.

I added links to the issue in Pydantic. https://github.com/pydantic/pydantic/issues/5824 https://github.com/python/typing_extensions/commit/fb37b2ee0ab56baf2dfd5df27aec0430435ba17f https://github.com/pydantic/pydantic/issues/5821#issuecomment-1558716103 https://github.com/pydantic/pydantic/issues/545#issuecomment-1573773542

for better location of error I added logs. It happens already when trying to import the Model Point

rypmaps-gateway-1  |   File "/varistar/./app/schemas/response_schemas.py", line 3, in <module>
rypmaps-gateway-1  |     from geojson_pydantic import Feature, Point
rypmaps-gateway-1  |   File "/usr/local/lib/python3.9/site-packages/geojson_pydantic/__init__.py", line 3, in <module>
rypmaps-gateway-1  |     from .features import Feature, FeatureCollection  # noqa
rypmaps-gateway-1  |   File "/usr/local/lib/python3.9/site-packages/geojson_pydantic/features.py", line 9, in <module>
rypmaps-gateway-1  |     from geojson_pydantic.geometries import Geometry, GeometryCollection
rypmaps-gateway-1  |   File "/usr/local/lib/python3.9/site-packages/geojson_pydantic/geometries.py", line 114, in <module>
rypmaps-gateway-1  |     class Point(_GeometryBase):
rypmaps-gateway-1  |   File "pydantic/main.py", line 204, in pydantic.main.ModelMetaclass.__new__
rypmaps-gateway-1  |   File "pydantic/fields.py", line 488, in pydantic.fields.ModelField.infer
rypmaps-gateway-1  |   File "pydantic/fields.py", line 419, in pydantic.fields.ModelField.__init__
rypmaps-gateway-1  |   File "pydantic/fields.py", line 534, in pydantic.fields.ModelField.prepare
rypmaps-gateway-1  |   File "pydantic/fields.py", line 638, in pydantic.fields.ModelField._type_analysis
rypmaps-gateway-1  |   File "/usr/local/lib/python3.9/typing.py", line 852, in __subclasscheck__
rypmaps-gateway-1  |     return issubclass(cls, self.__origin__)
rypmaps-gateway-1  | TypeError: issubclass() arg 1 must be a class

code:

from geojson_pydantic import FeatureCollection, Point

Thank you for your help.

ondrej-ivanko commented 2 months ago

A workaround is using no_type_check decorator from typing

from typing import no_type_check

from geojson_pydantic import FeatureCollection, Point
no_type_check(Point)
vincentsarago commented 2 months ago

@ondrej-ivanko I guess you're using geojson-pydantic 0.6

I'll be happy to review any PR patching 0.6 with a fix 🙏