This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author eric.snow
Recipients brett.cannon, christian.heimes, eric.snow, lemburg, minrk, ncoghlan, paul.moore, r.david.murray, tdsmith, vstinner
Date 2015-07-02.16:18:33
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1435853914.53.0.991253802011.issue24534@psf.upfronthosting.co.za>
In-reply-to
Content
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 <martin@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.
History
Date User Action Args
2015-07-02 16:18:34eric.snowsetrecipients: + eric.snow, lemburg, brett.cannon, paul.moore, ncoghlan, vstinner, christian.heimes, r.david.murray, minrk, tdsmith
2015-07-02 16:18:34eric.snowsetmessageid: <1435853914.53.0.991253802011.issue24534@psf.upfronthosting.co.za>
2015-07-02 16:18:34eric.snowlinkissue24534 messages
2015-07-02 16:18:33eric.snowcreate