Eric Snow added the comment:

FYI, support for .pth has been around since at least Python 2.0.  However, 
support for imports in .pth files was added in 2.1:

changeset:   15815:868d2acf745808c9033f57cd5829d97a69ecf56e
branch:      legacy-trunk
user:        Martin v. Löwis <mar...@v.loewis.de>
date:        Thu Jan 11 13:02:43 2001 +0000
summary:     Patch #103134: Support import lines in pth files.

>From what I understand .pth file weren't meant to be used in the way they are. 
> Some folks are just really good at exploiting unintended behaviors based on 
>an implementation. :)  We've been stuck with the "feature" ever since.

In this case the implementation happened to be a bit lax in how it evaluated 
each line.  It should have been strict about allowing only single import 
statements.  Instead it just made sure the line started with "import" and then 
exec'ed it.  A check for ";" would have been sufficient.

That said, I don't fault Martin (or whoever actually wrote it) at all. The 
implementation doesn't really bother me.  Sure, it could have been more 
careful, but honestly how could anyone be expected to anticipate the 
consequence here.

Ultimately, folks that looked closely enough at the source to figure out the 
hack would have had enough context to know the intent.  They should have opened 
a bug report rather that take advantage of the loophole.  If their need was 
sufficient they could have easily proposed an explicit mechanism to get what 
they wanted.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue24534>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to