[openstack-dev] HACKING and new-style relative imports

Kieran Spear kispear at gmail.com
Wed Jul 10 04:36:43 UTC 2013


On 10 July 2013 00:55, Joe Gordon <joe.gordon0 at gmail.com> wrote:
> 
> On Tue, Jul 9, 2013 at 1:28 PM, Kieran Spear <kispear at gmail.com> wrote:
>> 
>> Hi all,
>> 
>> There's a review up to make Horizon pass H304 (no relative imports):
>> 
>> https://review.openstack.org/#/c/35664/
>> 
>> Old-style relative imports are dangerous, but I can't think of a good
>> enough reason to forbid new-style imports, e.g.:
>> 
>> from .views import IndexView
>> 
>> instead of
>> 
>> from openstack_dashboard.dashboards.project.images_and_snapshots.views \
>>      import IndexView
>> 
>> particularly in Horizon where nesting is deep and you otherwise end up
>> with many imports that won't fit into 80 characters. I think if we're going
>> to make the change above the benefits would need to outweigh the effect on
>> readability.
>> 
>> There's some discussion on the review already, but I'd like to hear from a
>> more general audience. Thoughts?
> 
> 
> 
> http://google-styleguide.googlecode.com/svn/trunk/pyguide.html#Imports
> 
> "Do not use relative names in imports. Even if the module is in the same
> package, use the full package name. This helps prevent unintentionally
> importing a package twice."

Thanks. My understanding is that a module can only be imported twice if there are two different paths to it in your python path. This can happen with both relative and absolute imports, so I don't think H304 prevents that one.

> 
> 
>> 
>> 
>> Cheers,
>> Kieran
>> 
>> 
>> _______________________________________________
>> OpenStack-dev mailing list
>> OpenStack-dev at lists.openstack.org
>> http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev
> 
> 
> 
> _______________________________________________
> OpenStack-dev mailing list
> OpenStack-dev at lists.openstack.org
> http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev
> 



More information about the OpenStack-dev mailing list