-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
typing_extensions #37119
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
Comments
So if I do |
Can you also explain what it means to "make it a dependency"? Is that only a developer dependency for when you want to do type checking? Or would it actually be a runtime dependency? |
If I import |
I'm not aware of any way to make it a dev-only dependency. AFAIK it would have to be runtime-importable. |
And the import can't be hidden behind a |
That's a neat idea, but doesn't do it. |
And can you explain why it doesn't do it? (see also my second sentence in the comment above) (I don't know much about typing, just asking questions) |
i did this in https://github.com/pandas-dev/pandas/pull/27646/files/9aa69fe5491e0b161e679c8f54cbb8f13a48b85a didn't get any support at the time follow conversation from #27646 (comment) onwards |
see also #34869 (comment) for more discussion and a reference to similar workaround used by pytest for Protocol. |
So that seems certainly doable then to have mypy_extensions as a dev dependency, without having it as a runtime dependency |
and we no longer need to add it explicitly to environment.yaml see #27646 (comment) |
I don't know, can only confirm that I tried it and it didn't work.
@simonjayhawkins this looks really similar to Joris's suggestion which I was not able to implement succesfully. My prior has nonzero weight on "me messing up", can you confirm whether or not this is viable for us? |
I'm not sure if we could do everything that we could do if having typing_extensions as a runtime dependency would allow. but if having a runtime dependency is a definite no-no, then some more investigation of possible workarounds is worthwhile. as a start, have opened #37137 as a POC for Literal in function signatures. |
Is it definitely a no-no? Not that this is a definite reason to include it, but for reference, https://github.com/psf/black/blob/df4dd38a9a2b44c14485948fe8209fa19db2383a/setup.py install_requires=[
"click>=7.1.2",
"appdirs",
"toml>=0.10.1",
"typed-ast>=1.4.2",
"regex>=2020.1.8",
"pathspec>=0.6, <1",
"dataclasses>=0.6; python_version < '3.7'",
"typing_extensions>=3.7.4; python_version < '3.8'",
"mypy_extensions>=0.4.3",
], |
re-opening as discussion about having typing_extensions as a dev only dependency or using other workarounds is ongoing. |
Hi @simonjayhawkins - why not make it a runtime dependency? Wouldn't that be needed to be able to access I realise that there needs to be a really high bar for adding an extra runtime dependency, and this is one case where I think it would really be worth it:
Perhaps this is best discussed in the next dev meeting? tagging @pandas-dev/pandas-core @pandas-dev/pandas-triage in case anyone hasn't seen this and has input EDIT: just saw #37137, which |
You can just dummy these for Python < 3.8 Something like
Edit: Soft dependency only needed if developing/type checking on Python 3.7 |
@MarcoGorelli I don't think |
See #37137 though, it seems to work fine there e.g. from __future__ import annotations
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from typing import Literal
def foo(a: Literal[True]) -> None: ... runs fine in Python3.7, but fails if you remove |
This has been discussed many times before. I have no objection, but others do. by all means we can discuss again, but would need to get @TomAugspurger and @WillAyd to agree |
Does it type check in Python 3.7? |
Since we're a central part of the scientific python ecosystem, we should have a high bar for taking on dependencies. IMO this doesn't meet that bar. |
As in, can you run Anyway, it seems that if TYPE_CHECKING:
from typing import Literal works for both running the code, and for type checking it, so it should be OK to avoid adding this as a requirement. If all that needs to be done until Python3.7 is dropped is to place some imports under I think this can be closed then - if placing these imports under |
My experince in using Maybe someone could corroborate my experiece and see if they see something I didn't? |
|
ATM we vendor typing_extensions but mypy doesnt recognize it, so we can't actually use it. We should either remove it or make it a dependency.
The text was updated successfully, but these errors were encountered: