fluent icon indicating copy to clipboard operation
fluent copied to clipboard

Typehinting for IDE suggestions.

Open laundmo opened this issue 4 years ago • 3 comments

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?

laundmo avatar Aug 30 '21 12:08 laundmo

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?

dwt avatar Aug 30 '21 12:08 dwt

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 _?

laundmo avatar Aug 30 '21 15:08 laundmo

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.

dwt avatar Aug 30 '21 15:08 dwt