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

Typehinting for IDE suggestions. #10

Open
laundmo opened this issue Aug 30, 2021 · 3 comments
Open

Typehinting for IDE suggestions. #10

laundmo opened this issue Aug 30, 2021 · 3 comments

Comments

@laundmo
Copy link

laundmo commented Aug 30, 2021

Hey there,

i love the idea of this library. One issue though: there are no IDE autocomplete suggestions when using this.

I managed to get rudimentary suggestions to work by changing wrap to this:

WrappedT = typing.TypeVar('WrappedT')

def wrap(wrapped: WrappedT, *, previous=None) -> WrappedT:

sadly, this means i have to from fluentpy.wrapper import wrap as _ since type checkers dont understand the concept of a callable module, at least not the way you've done it. on the upside, i get autocomplete suggestions!

Would it be possible to add this to the library, maybe a bit more extensive to be able to see the Wrapper methods like .each? Maybe there's even a way to get it to work with the direct module import?

@dwt
Copy link
Owner

dwt commented Aug 30, 2021

Well, I don't use IDEs with autocompletion - so I couldn't really test yet - what are you using?

Do you have any pointers to the documentation what the autocomplete expects from a participating library?

In general, I think it would be rad to have autocomplete as that would make the library much more discoverable. I tend to use new libraries on a python-prompt to use introspection to understand how the libraries work, as there are still many (as you have discovered) concepts that an autocomplete can't grasp.

I would guess that executable modules may in general be problematic for autocomplete, as they pretty much require the execution of the code, as just parsing the AST doesn't expose that the module is (replaced at runtime) by a callable - but maybe there's a way to signal that to the autocompleter?

@laundmo
Copy link
Author

laundmo commented Aug 30, 2021

what are you using?

I'm using VSCode with the Pylance language server, which is based on Pyright.

Do you have any pointers to the documentation what the autocomplete expects from a participating library?

There's a bunch of PEPs that outline type hinting and related topics, I think a good idea would be to look at what Pyright implements: https://github.com/microsoft/pyright
PyCharm is another widely used IDE to consider, though im not well versed in that and don't know what tool they use.
Another autocomplete tool is Jedi, used in, for example, the ptpython prompt: https://jedi.readthedocs.io

Generally though, all of these tools will use python type hints, there's a great list of typing related thigns here: https://github.com/typeddjango/awesome-python-typing#articles

I have no idea for type checkers handling callable modules, there might be a way to typehint that it is callable, but I'm not sure.
Why did you go with a callable module and not just from fluentpy import _?

@dwt
Copy link
Owner

dwt commented Aug 30, 2021

Why did you go with a callable module and not just from fluentpy import _?

Well, because I could…, also from fluentpy import _ also works.

Well, maybe making the module executable wasn't so good an Idea, but I really liked it a the time. :/

I'll have a look at these autocompleters soon and see what can be done. In the meantime, I'll welcome more discussion and deeper pointers.

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

No branches or pull requests

2 participants