-
Notifications
You must be signed in to change notification settings - Fork 114
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
Use absolute imports #283
Use absolute imports #283
Conversation
|
||
#### In Runtime Code | ||
|
||
When a runtime file in this codebase needs to import another module/file in this codebase, you should import the absolute path of the module/file, not the relative one, using the `from X import Y` method. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you want to also allow for the possibility of importing the module without from
, e.g. import mypkg.sibling
and import mypkg.sibling as sister
? (I got the first example from pep-8)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For simplicity, I'd say no, let's not allow that, but I'm open to revisiting if there's a motivating use case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One motivation is for the tests use case where we use import pyteal as pt
or in general, importing many objects like from X import Y1, Y2, Y3, .... , Y30
and it gets pretty gnarly.
There is one obligatory use case: avoiding namespace collisions as was mentioned in the PEP itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jasonpaulos I'm on-board to try these options. Thanks for evaluating flake8-tidy-imports.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great improvement to code quality and ease of development!
Lately our relative imports have been a source of confusion/problems, and as of #273, absolute imports are now used by test code, so we might as well make the switch to absolute imports everywhere for consistency.
Though if there are objections, feel free to voice them.
Of particular note is the
CONTRIBUTING.md
file, in which I documented for the first time in this repo how our module and import conventions should work.