Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[python] Upgrade the imports in examples #220

Open
pamelafox opened this issue Mar 17, 2024 · 3 comments
Open

[python] Upgrade the imports in examples #220

pamelafox opened this issue Mar 17, 2024 · 3 comments
Labels
Language: Python Pertains to the Python implementation of TypeChat.

Comments

@pamelafox
Copy link
Member

Pyupgrade recommends:

import asyncio
from typing import Annotated, Literal, TypedDict

import dotenv
from typing_extensions import Doc

As everything but Doc has been in typing since 3.8 or 3.9:

https://docs.python.org/3/library/typing.html#typing.Literal

Apparently Doc is non-standard, interesting discussion on the PEP here:
https://discuss.python.org/t/pep-727-documentation-metadata-in-typing/32566/172

It seems unlikely to get accepted, but I assume its the only way to document when using TypedDict? That's what I saw in the examples.

@pamelafox
Copy link
Member Author

Ah but then there's a Pydantic error in 3.11:

Please use typing_extensions.TypedDict instead of typing.TypedDict on Python < 3.12

Dang! I'll just ignore my linter then / add a noqa. That might be worth mentioning in documentation about using TypeChat with TypedDict.

@DanielRosenwasser DanielRosenwasser added the Language: Python Pertains to the Python implementation of TypeChat. label Mar 18, 2024
@DanielRosenwasser
Copy link
Member

I assume its the only way to document when using TypedDict

So if you use Annotated[SomeType, Doc(...)] we recognize that. Some folks working on Python recommended we future-proof on that.

But we also just recognize Annotated[SomeType, "Some comment string."] because that's so common anyway (and it just feels better to use).

@pamelafox
Copy link
Member Author

Ah okay, I saw that mentioned in the Discourse thread but wasnt sure if that was also a standard. I recommend documenting both of those.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Language: Python Pertains to the Python implementation of TypeChat.
Projects
None yet
Development

No branches or pull requests

2 participants