Skip to content

✨ Add Typing for select of arbitrary length #839

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

Conversation

maxispeicher
Copy link

Running mypy or similar type checkers on select queries with more than 4 arguments will lead to errors due to the limited type overloads.

In order to at least somehow circumvent this, this PR adds overloads for an arbitrary amount of arguments to select.

resolves #92

@svlandeg svlandeg changed the title Add Typing for select of arbitrary length ✨ Add Typing for select of arbitrary length Mar 19, 2025
@GiorgioPorgio
Copy link

@Seluj78 I'm not sure if @maxispeicher is active these days and there were a few conflicts (filename changes) that I could not resolve on their branch, so I changed an open PR I had to be Maxi's changes without the conflicts.

Credits go to @maxispeicher ofc - it'd be awesome if we can get better typing :)

Thank you for your work!

@GiorgioPorgio
Copy link

GiorgioPorgio commented Mar 27, 2025

I do not think this can work unfortunately. Python's type system doesn't provide a clean way to have variadic generic types that preserve the individual types of each argument without listing all possibilities.

This approach would remove the type specificity of individual arguments and break a lot of consumers that rely on it.

@tiangolo
Copy link
Member

Thanks @maxispeicher and @GiorgioPorgio for the investigation and work on this! 🤓

Indeed, I had played around with this a lot and concluded that the best I could provide was some amount of overrides.

Unfortunately, because they can be of several types, it requires all the combinations, so adding each extra param supported is a combinatorial explosion, that's why there's only 4 now.

Hopefully with future improvements in the Python type system this could be solved. 🤓

For now, I'll pass on this. Thanks! ☕

@tiangolo tiangolo closed this Apr 27, 2025
@GiorgioPorgio
Copy link

Thanks for checking @tiangolo. Agreed, though I humbly recommend bumping it to 5. It's only 440 line diff. On 6 args it did explode. I have opened a PR for 5.

Thank you all for all the tools you build and maintain!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unexpected argument(s) warning in PyCharm when using select() with many parameters
6 participants