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

Add explanation of imports to API reference #1191

Closed
wants to merge 1 commit into from

Conversation

0xdade
Copy link

@0xdade 0xdade commented Jun 26, 2022

Yesterday, while trying to type check my code using the websockets library, I was getting quite frustrated. All of the example code seemed to show import websockets and then accessing everything directly off the package, which doesn't support type checking or code completion because of the lazy import system. I nearly opened an issue about the matter to see what I was doing wrong, when I then went to double check that there wasn't an existing issue about it before filing. Lo and behold, I found #940 (comment) which gave me what I needed to start type checking my code that uses websockets.

I couldn't find this directly provided as an example or in any of the example code I saw in the docs, but while digging around did see this reference to "use the real import path" at the bottom of the API reference index, without really elaborating on what that is. I consider myself a reasonably experienced python dev and was surprised/confused at first to see import websockets not exposing any of the modules to my IDE but from websockets import exposing all available modules (and thereby giving my autocomplete and letting mypy type check correctly).

So rather than just raise another issue complaining that I couldn't figure it out, I thought I'd add in a couple more lines to the docs to explain what "use the real import paths" actually looks like in code.

I also considered perhaps adding a note to the types page of the docs, but felt that wasn't really the correct place since that's a proper API reference. I also thought about maybe a new docs page in the how-to guides about how to use the websockets library in a way that your IDE and type checkers know what's going on, but thought I'd start with this simple change first.

@povilasb
Copy link

Thank you 🙌
It surely helped me.

@aaugustin
Copy link
Member

Addressed in 206d7ef. I chose to link to existing documentation rather than duplicate information.

@aaugustin
Copy link
Member

Thank you for the suggestion!

@aaugustin aaugustin closed this Feb 19, 2023
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

Successfully merging this pull request may close these issues.

3 participants