relative imports

14 views
Skip to first unread message

Randall

unread,
Feb 2, 2006, 2:08:46 PM2/2/06
to TurboGears
While browsing through the source code, I've seen lots of relative
imports, which is discouraged in the PEP 8 style guide.

- Relative imports for intra-package imports are highly
discouraged.
Always use the absolute package path for all imports.
(However, once PEP 328 [7] is fully implemented, its style of
explicit relative imports will be recommended.)

I think that Python 2.5 will issue deprication warnings, so it would be
a good idea to use absolute paths or do the from __future__ import
absolute_import thing. I know this could be a problem with Python 2.3,
but worth considering.

Randall

Kevin Dangoor

unread,
Feb 2, 2006, 2:12:31 PM2/2/06
to turbo...@googlegroups.com

Good catch. Can you open a ticket on this?

Thanks,
Kevin

fre...@pythonware.com

unread,
Feb 2, 2006, 3:05:53 PM2/2/06
to TurboGears
Randall wrote:

> While browsing through the source code, I've seen lots of relative
> imports, which is discouraged in the PEP 8 style guide.
>
> - Relative imports for intra-package imports are highly
> discouraged.
> Always use the absolute package path for all imports.
> (However, once PEP 328 [7] is fully implemented, its style of
> explicit relative imports will be recommended.)
>
> I think that Python 2.5 will issue deprication warnings

I find that a bit unlikely.

> so it would be a good idea to use absolute paths or do the from __future__
> import absolute_import thing.

What absolute_import thing ?

$ python2.4
Python 2.4.1 (#1, Aug 11 2005, 18:03:42)
>>> from __future__ import absolute_import
File "<stdin>", line 1
SyntaxError: future feature absolute_import is not defined

$ python2.5
Python 2.5a0 (trunk:42225M, Feb 2 2006, 21:01:41)
>>> from __future__ import absolute_import
SyntaxError: future feature absolute_import is not defined (<stdin>,
line 1)

> I know this could be a problem with Python 2.3,
> but worth considering.

Optimizing for Python 3.0 is a bit of a premature optimization...

</F>

Kevin Dangoor

unread,
Feb 2, 2006, 3:19:03 PM2/2/06
to turbo...@googlegroups.com
On 2/2/06, fre...@pythonware.com <fre...@pythonware.com> wrote:
>
> Randall wrote:
>
> > While browsing through the source code, I've seen lots of relative
> > imports, which is discouraged in the PEP 8 style guide.
> >
> > - Relative imports for intra-package imports are highly
> > discouraged.
> > Always use the absolute package path for all imports.
> > (However, once PEP 328 [7] is fully implemented, its style of
> > explicit relative imports will be recommended.)
> >
> > I think that Python 2.5 will issue deprication warnings
>
> I find that a bit unlikely.
>
> > so it would be a good idea to use absolute paths or do the from __future__
> > import absolute_import thing.
>
> What absolute_import thing ?
>
> $ python2.4
> Python 2.4.1 (#1, Aug 11 2005, 18:03:42)
> >>> from __future__ import absolute_import
> File "<stdin>", line 1
> SyntaxError: future feature absolute_import is not defined

Wow. That PEP appears to be very wrong.

Nevertheless, getting rid of relative imports in the code is a good plan.

Kevin

Reply all
Reply to author
Forward
0 new messages