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
Feature Request: Support for typing_extensions.Annotated (from PEP 593) #837
Comments
Also note: mypy has (And as long as we don't drop support for the @samuelcolvin It might be worth considering this option more seriously prior to releasing V1.0, in case it allows us to drop the |
That's interesting. Although it makes the code more verbose and (subjectively) less intuitive. I like that the |
@tiangolo I think that's a good point on both counts. At any rate, I think it should be possible to handle this more completely by way of a mypy plugin (I'm already using the plugin I've opened a PR for in pydantic in all my projects, and I plan to get it into a release-worthy state as soon as v1.0 drops). Given the limited scope of issues that type-hinting as That said, I think it may still make sense to support |
See my response on #824. My only other question: is there any change whatsoever that the pep get's declined and we're left with unofficial syntax? I guess if that does happen and mypy stops supporting |
In summary I'm keen to implement this, I think it should be backwards compatible so can happen after v1. As discussed on #824 and here, use of |
In recent versions And @dmontagu 's mypy plugin is working great. I would think this specific issue could be closed and we could open a new one if there's a new use case that benefits from |
PEP 593 is now in Python 3.9. Would this help to have better support for Pydantic in Pyright, Pylance and hence VS Code, making Option 2 of microsoft/python-language-server#1898 feasible? Field information could be basically stored in Best regards, Martin |
Would love to see Pylance and Pydantic playing nicely together without the decorator hack! |
No errors but Pylance still only sees |
As a test I put the decorator hack at the end of if TYPE_CHECKING:
from dataclasses import dataclass Now Pylance gives type hinting for this: from pydantic.dataclasses import dataclass
@dataclass
class Foo:
value1: str
value2: Annotated[str, Field(description="Something else")]
f = Foo("boo", value2="foo") All tests still pass, but I don't know if this has made mypy ignore any internal tests... |
Feature Request
Support for
typing_extensions.Annotated
(from PEP 593)This could offer a nice way to solve the problem of assigning a
Schema
to a field without upsetting mypy, and without introducing an auxiliary function returning typeAny
(as discussed in #577):Instead of
The API could be:
typing_extensions.Annotated
was added in mypy 0.730.typing_extensions.Annotated
.The text was updated successfully, but these errors were encountered: