[openstack-dev] [Horizon] HACKING.rst and import standards

Gabriel Hurley Gabriel.Hurley at nebula.com
Fri Jun 7 23:11:48 UTC 2013


> A topic not discussed is module-level import vs object-level import.
> While other core projects only use module-level import, Horizon uses both
> and object-level imports are widely used like below.

Yep, I had left that one out on purpose for a few reasons:

1. I (personally) find this to be a rule based more on dogma than actual improvement to readability/code quality. It often results in having to alias modules to shorter names, etc. to try and keep line lengths down, or having to type the name of module before a function every time you want to use it. I understand the arguments in favor of it, but it doesn't do much for me.

2. It would require a tremendous amount of rewriting (far more so than any of the fixes I *would* like to see turned on) for no practical gain.

3.  It's mostly a matter of taste. To that point, PEP8 indicates that both are completely valid and acceptable styles. Strictly enforcing it where it's actively making things less readable or less convenient is precisely the warning of "A Foolish Consistency is the Hobgoblin of Little Minds."

4.  Alphabetical one-import-per-line importing fixes most of the practical issues that module-level-only importing is supposed to fix, and most modern editors make it trivial to see where something was defined so the "know where things are defined" argument doesn't hold much weight.

If the rest of the contributor-base for Horizon strongly prefers that we enforce module-level-only importing then I am willing to listen, but without strong reason to do so I think we have much more fruitful things we could be working on.

That's mostly my personal two cents, and should not be taken as a commandment or decision upon the project.

All the best,

    - Gabriel



More information about the OpenStack-dev mailing list