-
Notifications
You must be signed in to change notification settings - Fork 119
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
Should we vendor typing_extensions.NotRequired? #1337
Comments
What's the motivation for this? Are they being removed from |
The motivation is to avoide the The Required/NotRequired are used in TypedDict definitions, which means that TypedDict's can't be used without quotes. Granted, those typed dicts are internal. I think it may partially help with the following comment for public typed dicts: The latter could be an improvement for our library users, maybe? Possibly related: #1336 |
We're uncertain whether this will actually work once they're vendored with Pyright. Investigate on a rainy day next cycle. |
I suspect that this can't be vendored, given the following quote from typing-extensions: "typing_extensions is treated specially by static type checkers such as mypy and pyright. Objects defined in typing_extensions are treated the same way as equivalent forms in typing." I haven't used if TYPE_CHECKING:
from typing_extensions import NotRequired As far as I can tell, typing_extensions currently supports Python versions 3.8 and higher, so do we really need Maybe the outcome (with a little bit of further rainy day investigation) will be closing this and making a new issue: let's use |
The advantage of this is that |
That makes sense. With Since we're going to go with |
perhaps that means we can't naively vendor some bits from typing_extensions. We could still play with a vendored module that happens to be called "typing_extensions" but I doubt that's worth the hassle, as we'd have to make a funky import to ensure we don't break charms that imports real type_extensions and thus has real module in their virtual env(s). my take: either real typing_extensions or nothing. |
The types using NotRequired are _Private in ops/pebble.py. Even if we wanted to make some of them public, we could probably use strings around our type annotations. But we don't think anything is needed here now. |
The code is really simple:
https://github.com/python/typing_extensions/blob/70cec91bec65155dc339d631ede2a933582558df/src/typing_extensions.py#L2220-L2256
We're using:
Required
in ops/charm.pyNotRequired
in ops/pebble.pyNotRequired
in test/fake_pebble.pyThe text was updated successfully, but these errors were encountered: