Skip to content
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

Increase IDE typing support #218

Open
ShadowJonathan opened this issue Jul 1, 2020 · 2 comments
Open

Increase IDE typing support #218

ShadowJonathan opened this issue Jul 1, 2020 · 2 comments
Labels
enhancement New feature or request not qualified The issue is not checked yet by the owners question Further information is requested

Comments

@ShadowJonathan
Copy link

ShadowJonathan commented Jul 1, 2020

Is your feature request related to a problem? Please describe.
In pycharm, as of this moment, rethinkdb query methods and others are not recognized properly in static analysis, and I think static typing analysis libraries such as mypy will not be able to validate code this way.

Describe the solution you'd like
Superclass RethinkDB with classes encapsulating ast, net, query, and errors submodules' functions and constants, erase this monkeypatching block of code:

        for module in (self.net, self.query, self.ast, self.errors):
            for function_name in module.__all__:
                setattr(self, function_name, getattr(module, function_name))

Add (generic/union) type annotations to chaining functions so that (for example; get_all cannot be chained with get_all, or with another function) IDE and static analysis can pick up on incorrect combinations before they happen.

Maybe possibly split RethinkDB into subclasses SyncRethinkDB, AsyncioRethinkDB, TwistedRethinkDB, TornadoRethinkDB and GeventRethinkDB that all annotate the return values of their ast functions with the correct types (Future, etc.) so that IDE compatibility and analysis can pick up on a possibly incorrect/incompatible versions.

Or simply have the connection type at run() influence the wrapping type around the return value.

Additional context
Zen of Python, line 2:

Explicit is better than implicit.

A lot of methods in the python driver puzzle me as a python developer, simplifying them to a set of ast frontend functions directly denoted in the RethinkDB class, and have the Connection type influence typing generics' outcome (run(Connection[RetT]) -> RetT[T]) could increase IDE typing analysis while staying flexible and open to new runtime types.

@ShadowJonathan ShadowJonathan added enhancement New feature or request not qualified The issue is not checked yet by the owners question Further information is requested labels Jul 1, 2020
@dpineiden
Copy link
Contributor

How works pycharm? What require to identify the methods?
I guess is a pycharm problem maybe.
The second could be a good idea, maybe wrapping to classes more explicit could help

@gabor-boros
Copy link
Member

Yep, the python driver is not built in the mentality of Zen of Python, that's sure.

I think if we could move to Python 3 and type hint the code that would help a lot. Also, refactoring (partially what @ShadowJonathan mentioned) is necessary too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request not qualified The issue is not checked yet by the owners question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants