-
Notifications
You must be signed in to change notification settings - Fork 105
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
Improve typing of run() #580
base: master
Are you sure you want to change the base?
Conversation
Hi, thanks for this PR, I'm not opposed to such a change, but I'm a big worried the duplication will cause issues. (we'll update a signature and forget to update the other). I'm happy to merge such a change when we drop support to python 3.10 (~1.5 years for now). Sorry for that, we need to keep the project as low-maintenance as possible |
As I mention in the description, if you don't mind a partial loss of typing information on Python <3.11, then we can remove that duplication today. So Python 3.11+ gets the full typing support with correct return types, while older version of Python will see |
I understand, but that would be considered a regression. And python 3.10 is still alive for two more years, so those users are still first class citizens in the eyes of the project. We'll stay with the status quo for a bit longer |
No problem, I'll leave it up to you. But, from my perspective, the loss on 3.10 is minor (essentially |
There is no problem to use |
That is also an option, yes. From looking around the project, it seemed like it was avoiding adding a new dependency on typing_extensions. @gabrieldemarmiesse Would you be fine with adding typing-extensions for Python <3.12? |
We already have typing-extensions as a dependency, feel free to use it :) |
Ah, maybe I misread it earlier. Will update later. |
That should be fine now. I'd note that it's probably worth introducing mypy to the project. I tried to check the code with mypy and there appeared to be >200 type errors already present in the code (without adding an extra strictness settings). |
Thank you, before merging this, I'll try to see how it behaves in different IDEs. You don't need to do anything, I'm just running some tests to see if it's well supported :) |
Sorry for the huge delay. I tried your PR with Pycharm and here is what I get: As you can see, pycharm sees So I'm all for improving the typing experience, so in my eyes this PR still has a lot of value, but we'll wait until at vscode and pycharm both can understand the function signature before pushing forward. I think you can convert this pull request to "Draft" and we'll reopen it when the two majors IDEs support this feature. Does that sound good to you? |
I feel like we have different priorities. As someone that is checking code with mypy and trying to have type safe code, the current state is unusable, as you will always get type errors due to the return type being incorrect. Whereas seeing the kwargs in an IDE seems like a nice-to-have, you can always look at the documentation if it's missing. But, a quick search suggests that Pycharm 2024.1.2 already has support: https://blog.jetbrains.com/pycharm/2024/05/pycharm-2024-1-2/#code-assistance-for-typeddict-and-unpack I'm pretty sure VSCode is built on top of pyright, which has supported Unpack for probably atleast a year, so I'd also be surprised if that really doesn't work with it (maybe it will error when you put the wrong kwarg in, even if it doesn't display the kwargs?). |
So, looks like you were one patch release short of the Unpack support. |
I'll retry it then, thanks for the info!
…On Sun, 21 Jul 2024, 13:51 Sam Bull, ***@***.***> wrote:
pycharm 2024.1.1
So, looks like you were one patch release short of the Unpack support.
—
Reply to this email directly, view it on GitHub
<#580 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ADCLMK4CU67IPBM34MGZMGLZNOOETAVCNFSM6AAAAABGQSZY7OVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDENBRGU4DCNJVGE>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
@Dreamsorcerer I retried and it works on VSCode and Pycharm :) I think we can merge this PR. Can you rebase/merge master into your branch? Afterwards we should be good to go :) |
I forgot to check if the documentation generation works well with it. I'm sorry about that, the PR has far reaching consequences that are sometimes hard to find. |
It seems we lose all the default values for the arguments in the docs. It looks like this now: I wonder if it's better to duplicate all the default values in the docstring, or to just say that we won't be mypy-compatible until Python creates a typing feature that allows us to dedupe arguments in overloads. I'll think about it. |
Yes, that'd be expected. I'm not aware of any plans currently to introduce defaults in this way, so I wouldn't want to wait on that. |
The vast majority of them default to |
FWIW I agree with @gabrieldemarmiesse in being hesitant about this change... It's a slight sacrifice of readability in the function signature for the sake of cutting-edge and slightly immature typing features, not a totally obvious choice to me. I understand the issue with using a type checker under status quo, but I just use |
Sure, but then you have no type safety. A safer approach would be litter the code with isinstance() asserts, but it's rather annoying and unnecessary when the correct information is available. |
Having been using this package in a more tightly type-checked codebase I'd like to take back my hesitation and make myself +1 for this kind of change. Python's typing is unquestionably problematic in some areas, but in this case I agree with @Dreamsorcerer that this provides net benefit.
I'm on board with this for this case where defaults are generally unimportant, simply representing "not passed". (In fact, the distinction between "not passed" and "default value" should be made clearer with all args defaulting to Could we add overloads for |
No description provided.