-
-
Notifications
You must be signed in to change notification settings - Fork 845
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
Structure imports in __init__.py #3365
Conversation
Ruff supports sorting |
Okay, perhaps we shouldn't take this approach? I found it a useful as was thinking about how to structure the docs, and remaining places where we have potential for API improvements. An alternative might be to leave |
I don't have strong feelings, it's easy enough to revert in the future if we learn this ordering is hard to maintain. I just wanted to point out that automation exists. A docstring seems sensible too. What value is there to ascribing contents to specific submodules? There's also the option to do something like: # Top level API. `_api.py`
_api = [
"delete",
"get",
"head",
"options",
"patch",
"post",
"put",
"request",
"stream",
]
# Authentication. `_auth.py`
_auth = [
"Auth",
"BasicAuth",
"DigestAuth",
"NetRCAuth",
]
__all__ = _api + _auth or from ._api import __all__ as __all__api
from ._auth import __all__ as __all__auth
__all__ = __all__api + __all__auth or __all__ = _api.__all__ + _auth.__all__ I'd need to double check but I'm pretty sure these formats are generally supported by type checkers and language servers. |
There's also switching from from ._api import (
delete as delete,
get as get,
head as head,
options as options,
patch as patch,
post as post,
put as put,
request as request,
stream as stream,
) There's a nice summary of the supported interface declarations in the Pyright docs |
👋 Zanie asked for my thoughts here -- I authored the Ruff rule sorting
Yeah, the Ruff rule tries very hard to preserve comments. But it doesn't understand using comments between In terms of the
Aesthetically my personal preference is to define |
Thanks @zanieb, @AlexWaygood. Not exactly obvious to me what'd be neatest here, so I'll just pass on this change for now. |
Closes #3352