Commit Graph

231 Commits

Author SHA1 Message Date
Benjamin Peterson e8e14591eb rather than passing locals to the class body, just execute the class body in the proper environment 2013-05-16 14:37:25 -05:00
Benjamin Peterson 312595ce3a hide the __class__ closure from the class body (#12370) 2013-05-15 15:26:42 -05:00
Brett Cannon 4c14b5de1c #17115,17116: Have modules initialize the __package__ and __loader__
attributes to None.

The long-term goal is for people to be able to rely on these
attributes existing and checking for None to see if they have been
set. Since import itself sets these attributes when a loader does not
the only instances when the attributes are None are from someone
overloading __import__() and not using a loader or someone creating a
module from scratch.

This patch also unifies module initialization. Before you could have
different attributes with default values depending on how the module
object was created. Now the only way to not get the same default set
of attributes is to circumvent initialization by calling
ModuleType.__new__() directly.
2013-05-04 13:56:58 -04:00
Benjamin Peterson 3b0431dc60 check local class namespace before reaching for cells (closes #17853) 2013-04-30 09:41:40 -04:00
Brett Cannon edfd6ae79c Issue #17244: Don't mask exceptions raised during the creation of
bytecode files in py_compile.

Thanks to Arfrever Frehtes Taifersar Arahesis for the bug report.
2013-04-14 12:48:15 -04:00
Brett Cannon 100883f0cb Issue #17093,17566,17567: Methods from classes in importlib.abc now raise/return
the default exception/value when called instead of raising/returning
NotimplementedError/NotImplemented (except where appropriate).
This should allow for the ABCs to act as the bottom/end of the MRO with expected
default results.

As part of this work, also make importlib.abc.Loader.module_repr()
optional instead of an abstractmethod.
2013-04-09 16:59:39 -04:00
Brett Cannon daf4daa295 merge 2013-04-01 13:25:40 -04:00
Brett Cannon f8ffec0617 Issue #17357: Add missing verbosity messages when running under
-v/-vv that were lost in the transition to importlib.
2013-04-01 13:10:51 -04:00
Victor Stinner 765531d2d0 Issue #17516: use comment syntax for comments, instead of multiline string 2013-03-26 01:11:54 +01:00
Benjamin Peterson 440282ba8a copy 2.7 magic numbers for historical interest 2013-03-21 23:04:45 -05:00
Brett Cannon 4802becb16 Issue #17117: Have both import itself and importlib.util.set_loader()
set __loader__ on a module when set to None.

Thanks to Gökcen Eraslan for the fix.
2013-03-13 10:41:36 -07:00
Brett Cannon c190389834 Issue #17220: two fixes for changeset 2528e4aea338.
First, because the mtime can exceed 4 bytes, make sure to mask it down to 4
bytes before getting its little-endian representation for writing out to a .pyc
file.

Two, cap an rsplit() call to 1 split, else can lead to too many values being
returned for unpacking.
2013-02-25 17:10:11 -05:00
Serhiy Storchaka 39e47f94ec Issue #17220: Little cleanup of _bootstrap.py. 2013-02-25 15:40:33 +02:00
Eric Snow 5df9f82547 Merge from 3.3 2013-02-16 22:25:31 -07:00
Eric Snow 5b49962f7e Fixes a FileFinder docstring to reflect an old change.
That change was in 1db6553f3f8c.
2013-02-16 22:23:48 -07:00
Benjamin Peterson 419d9a83d5 evaluate lambda keyword-only defaults after positional defaults (#16967 again) 2013-02-10 09:48:22 -05:00
Benjamin Peterson 1ef876cd28 evaluate positional defaults before keyword-only defaults (closes #16967) 2013-02-10 09:29:59 -05:00
Brett Cannon 85ae3566d1 Merge w/ 3.3 more fixes thanks to issue #17098 2013-02-01 16:36:29 -05:00
Brett Cannon da9cf0eef8 Issue #17098: Be more stringent of setting __loader__ on early imported
modules. Also made test more rigorous.
2013-02-01 15:31:49 -05:00
Brett Cannon 611afc1b3f Issue #17098: all modules should have __loader__ 2013-02-01 14:07:28 -05:00
Brett Cannon 0ecd30b4af Issue #17098: Make sure every module has __loader__ defined.
Thanks to Thomas Heller for the bug report.
2013-02-01 14:04:12 -05:00
Brett Cannon f3220d6af7 Tweak an exception message 2013-01-27 13:04:56 -05:00
Brett Cannon 14581d5dc4 Port py_compile over to importlib 2013-01-26 08:48:36 -05:00
Brett Cannon 686e880f20 Touch up exception messaging 2013-01-25 13:49:19 -05:00
Brett Cannon 569ff4fbbc Issue #15031: Refactor some code in importlib pertaining to validating
and compiling bytecode.

Thanks to Ronan Lamy for pointing the redundancy and taking an initial
stab at the refactor (as did Nick Coghlan).
2013-01-11 18:09:25 -05:00
Brett Cannon c57f9f9419 Merge from 3.3 for fix for issue #16730 2013-01-11 15:42:30 -05:00
Brett Cannon a9976b3e32 Issue #16730: Don't raise an exception in
importlib.machinery.FileFinder when the directory has become
unreadable or a file. This brings semantics in line with Python 3.2
import.

Reported and diagnosed by David Pritchard.
2013-01-11 15:40:12 -05:00
Andrew Svetlov f7a17b48d7 Replace IOError with OSError (#16715) 2012-12-25 16:47:37 +02:00
Andrew Svetlov 2606a6f197 Issue #16719: Get rid of WindowsError. Use OSError instead
Patch by Serhiy Storchaka.
2012-12-19 14:33:35 +02:00
Eric Snow a6cfb28bd2 Issue #15627: This is simply an update to the name of a new method recently added
to importlib.abc.SourceLoader.
2012-12-04 23:43:43 -08:00
Barry Warsaw b72c10996e - Issue #16514: Fix regression causing a traceback when sys.path[0] is None
(actually, any non-string or non-bytes type).
2012-11-20 15:35:27 -05:00
Barry Warsaw 82c1c781c7 - Issue #16514: Fix regression causing a traceback when sys.path[0] is None
(actually, any non-string or non-bytes type).
2012-11-20 15:22:51 -05:00
Brett Cannon 5650e4f41c Issue #15627: Add the compile_source() method to
importlib.abc.SourceLoader.

This provides an easy hook into the import system to allow for source
transformations, AST optimizations, etc.
2012-11-18 10:03:31 -05:00
Benjamin Peterson 29824550b1 merge 3.3 2012-11-12 16:48:25 -05:00
Benjamin Peterson debf64ce2b missing letter 2012-11-12 16:48:17 -05:00
Nick Coghlan d4f5ad6c6e Merge fix from #6074 from 3.3 2012-10-19 23:36:15 +10:00
Nick Coghlan eb8d627bbd Issue #6074: Apply an appropriate fix for importlib based imports 2012-10-19 23:32:00 +10:00
Trent Nelson 744faddae8 Merge issue #15833: don't raise an exception if importlib can't write
byte-compiled files.

This fixes a regression introduced by 3.3.

Patch by Charles-François Natali.
2012-10-16 08:03:21 -04:00
Trent Nelson d783c8ed00 Issue #15833: don't raise an exception if importlib can't write byte-compiled
files.

This fixes a regression introduced by 3.3.  Patch by Charles-François Natali.
2012-10-16 07:47:34 -04:00
Brett Cannon 6072e0bf42 Remove uses of % with str.format. 2012-10-12 10:00:34 -04:00
Brett Cannon 9407d50208 Merge fix for issue #15111. 2012-10-10 19:18:37 -04:00
Brett Cannon a6ce4fd426 Closes issue #15111: Calling __import__ with a module specified in
fromlist which causes its own ImportError (e.g. the module tries to
import a non-existent module) should have that exception propagate.
2012-10-10 19:03:46 -04:00
Jesus Cea 4791a24268 #16135: Removal of OS/2 support (Python code partial cleanup) 2012-10-05 03:15:39 +02:00
Brett Cannon 8ed677db12 Add some comments. 2012-09-28 16:41:39 -04:00
Benjamin Peterson 52c62d8697 rephrase 2012-09-26 00:25:10 -04:00
Benjamin Peterson feaa54f537 don't depend on __debug__ because it's baked in at freeze time (issue #16046) 2012-09-25 11:22:59 -04:00
Antoine Pitrou 4f0338cab7 Issue #15781: Fix two small race conditions in import's module locking. 2012-08-28 00:24:52 +02:00
Brett Cannon 12c6bda4f0 Issue #15316: Let exceptions raised during imports triggered by the
fromlist of __import__ propagate.

The problem previously was that if something listed in fromlist didn't
exist then that's okay. The fix for that was too broad in terms of
catching ImportError.

The trick with the solution to this issue is that the proper
refactoring of import thanks to importlib doesn't allow for a way to
distinguish (portably) between an ImportError because finders couldn't
find a loader, or a loader raised the exception. In Python 3.4 the
hope is to introduce a new exception (e.g. ModuleNotFound) to make it
clean to differentiate why ImportError was raised.
2012-08-24 18:25:59 -04:00
Brett Cannon ba0a3edd26 Issue #2051: Tweak last commit for this issue to pass in mode instead
of source path to set_data() and make the new argument private until
possible API changes can be discussed more thoroughly in Python 3.4.
2012-08-24 13:48:39 -04:00
Nick Coghlan a508770e20 Close #2501: Permission bits are once again correctly copied from the source file to the cached bytecode file. Test by Eric Snow. 2012-08-24 18:32:40 +10:00