GraiaProject / Avilla

The next-gen framework for IM development. Powered by Graia Project.
MIT License
160 stars 14 forks source link

Twilight 在 Pydantic V2 环境运行的问题 #130

Closed Redlnn closed 1 year ago

Redlnn commented 1 year ago

avilla.twilight.twilight 中使用了 from pydantic.utils import Representation

但 Pydantic V2 中该类已被移动,应使用 from pydantic.v1.utils import Representation

是否可以这样改呢,这样改的话 Pylance 在环境是 Pydantic V1 时会乱叫,或者有无更优雅的实现?

- from pydantic.utils import Representation
+ from pydantic.version import VERSION as PYDANTIC_VERSION

...

+ if int(PYDANTIC_VERSION[0]) >= 2:
+     from pydantic.v1.utils import Representation
+ else:
+     from pydantic.utils import Representation

image

GreyElaina commented 1 year ago

if TYPE_CHECKING. it really works.

PRs welcome.

GreyElaina commented 1 year ago

and fix the missing dep plz