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

Standardize import style #478

Open
c24t opened this issue Jan 31, 2019 · 7 comments
Open

Standardize import style #478

c24t opened this issue Jan 31, 2019 · 7 comments

Comments

@c24t
Copy link
Member

c24t commented Jan 31, 2019

The google python style guide recommends against importing classes. This makes it clear which namespace defines each class, but is cumbersome and leads to ugly workarounds for common namespace names (e.g. ... import view as view_module).

Most modules have a consistent internal import style, but there's no consistent style across the library. We should decide whether to follow the style guide everywhere or break from it everywhere.

@reyang
Copy link
Contributor

reyang commented Feb 14, 2019

We might need to change the import path due to the refactoring work in #445 (potential breaking changes).

@kshithijiyer
Copy link

I feel standardizing imports as per pep8 standards would be better.
https://www.python.org/dev/peps/pep-0008/

@reyang
Copy link
Contributor

reyang commented May 11, 2019

@kshithijiyer would you explain why you would prefer pep8?

@c24t @lzchen @songy23 how do you think?

@kshithijiyer
Copy link

kshithijiyer commented May 11, 2019

Pep8 standard in general improves code readability. Apart from that, it has now become the standard for python code. I would say that the standard mentioned in the previous comments is good but creates an issue when we actually import everything into the namespace. For example, if you wish to use randint function from random module following the previous standard says you can do an import random by doing so you actually import a lot of unnecessary functions which will never be used inside the namespace as well. Whereas pep8 says never to use from <module> import * which is the same as import <module>. Hence looking at this I personally feel it's better to use pep8 instead of going with any other standard.

@c24t
Copy link
Member Author

c24t commented May 13, 2019

We already follow PEP 8, this ticket is about consistently importing either classes or modules.

you actually import a lot of unnecessary functions which will never be used inside the namespace as well

Whether you import the module or individual functions/classes the import machinery creates the module object and executes the code, there's no reason to prefer importing individual functions/classes except personal style.

pep8 says never to use from <module> import * which is the same as import <module>

import * binds all names defined in the imported module, import foo binds the module object itself.

@dineshkrishnareddy
Copy link
Contributor

dineshkrishnareddy commented Oct 3, 2019

hey @c24t @kshithijiyer @reyang can I work on this?

@reyang
Copy link
Contributor

reyang commented Oct 3, 2019

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

No branches or pull requests

4 participants