Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
82da8886
Commit
82da8886
authored
Jul 04, 2013
by
Brett Cannon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #15767: Revert 3a50025f1900 for ModuleNotFoundError
parent
45091c0a
Changes
10
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
807 additions
and
842 deletions
+807
-842
Doc/c-api/exceptions.rst
Doc/c-api/exceptions.rst
+0
-7
Doc/library/exceptions.rst
Doc/library/exceptions.rst
+1
-2
Doc/reference/import.rst
Doc/reference/import.rst
+6
-6
Doc/whatsnew/3.4.rst
Doc/whatsnew/3.4.rst
+2
-1
Include/pyerrors.h
Include/pyerrors.h
+0
-3
Lib/importlib/_bootstrap.py
Lib/importlib/_bootstrap.py
+1
-1
Misc/NEWS
Misc/NEWS
+0
-4
Python/errors.c
Python/errors.c
+3
-22
Python/import.c
Python/import.c
+1
-2
Python/importlib.h
Python/importlib.h
+793
-794
No files found.
Doc/c-api/exceptions.rst
View file @
82da8886
...
@@ -292,13 +292,6 @@ in various ways. There is a separate error indicator for each thread.
...
@@ -292,13 +292,6 @@ in various ways. There is a separate error indicator for each thread.
.. versionadded:: 3.3
.. versionadded:: 3.3
.. c:function:: PyObject* PyErr_SetImportErrorSubclass(PyObject *msg, PyObject *name, PyObject *path)
Much like :c:func:`PyErr_SetImportError` but this function allows for
specifying a subclass of :exc:`ImportError` to raise.
.. versionadded:: 3.4
.. c:function:: void PyErr_SyntaxLocationEx(char *filename, int lineno, int col_offset)
.. c:function:: void PyErr_SyntaxLocationEx(char *filename, int lineno, int col_offset)
...
...
Doc/library/exceptions.rst
View file @
82da8886
...
@@ -185,8 +185,7 @@ The following exceptions are the exceptions that are usually raised.
...
@@ -185,8 +185,7 @@ The following exceptions are the exceptions that are usually raised.
A subclass of :exc:`ImportError` which is raised by :keyword:`import` when a
A subclass of :exc:`ImportError` which is raised by :keyword:`import` when a
module could not be located. This includes ``from ... import`` statements as
module could not be located. This includes ``from ... import`` statements as
the specific attribute being requested cannot be known a priori to be a module
the specific attribute being requested cannot be known a priori to be a module
or some other type of object. It is also raised when ``None`` is found in
or some other type of object.
:data:`sys.modules`.
.. versionadded:: 3.4
.. versionadded:: 3.4
...
...
Doc/reference/import.rst
View file @
82da8886
...
@@ -37,7 +37,7 @@ use the standard import system.
...
@@ -37,7 +37,7 @@ use the standard import system.
When
a
module
is
first
imported
,
Python
searches
for
the
module
and
if
found
,
When
a
module
is
first
imported
,
Python
searches
for
the
module
and
if
found
,
it
creates
a
module
object
[#
fnmo
]
_
,
initializing
it
.
If
the
named
module
it
creates
a
module
object
[#
fnmo
]
_
,
initializing
it
.
If
the
named
module
cannot
be
found
,
an
:
exc
:`
ModuleNotFound
Error
`
is
raised
.
Python
implements
various
cannot
be
found
,
an
:
exc
:`
Import
Error
`
is
raised
.
Python
implements
various
strategies
to
search
for
the
named
module
when
the
import
machinery
is
strategies
to
search
for
the
named
module
when
the
import
machinery
is
invoked
.
These
strategies
can
be
modified
and
extended
by
using
various
hooks
invoked
.
These
strategies
can
be
modified
and
extended
by
using
various
hooks
described
in
the
sections
below
.
described
in
the
sections
below
.
...
@@ -168,7 +168,7 @@ arguments to the :keyword:`import` statement, or from the parameters to the
...
@@ -168,7 +168,7 @@ arguments to the :keyword:`import` statement, or from the parameters to the
This name will be used in various phases of the import search, and it may be
This name will be used in various phases of the import search, and it may be
the dotted path to a submodule, e.g. ``foo.bar.baz``. In this case, Python
the dotted path to a submodule, e.g. ``foo.bar.baz``. In this case, Python
first tries to import ``foo``, then ``foo.bar``, and finally ``foo.bar.baz``.
first tries to import ``foo``, then ``foo.bar``, and finally ``foo.bar.baz``.
If any of the intermediate imports fail, an :exc:`
ModuleNotFound
Error` is raised.
If any of the intermediate imports fail, an :exc:`
Import
Error` is raised.
The module cache
The module cache
...
@@ -187,7 +187,7 @@ object.
...
@@ -187,7 +187,7 @@ object.
During import, the module name is looked up in :data:`sys.modules` and if
During import, the module name is looked up in :data:`sys.modules` and if
present, the associated value is the module satisfying the import, and the
present, the associated value is the module satisfying the import, and the
process completes. However, if the value is ``None``, then an
process completes. However, if the value is ``None``, then an
:exc:`
ModuleNotFound
Error` is raised. If the module name is missing, Python will
:exc:`
Import
Error` is raised. If the module name is missing, Python will
continue searching for the module.
continue searching for the module.
:data:`sys.modules` is writable. Deleting a key may not destroy the
:data:`sys.modules` is writable. Deleting a key may not destroy the
...
@@ -195,7 +195,7 @@ associated module (as other modules may hold references to it),
...
@@ -195,7 +195,7 @@ associated module (as other modules may hold references to it),
but it will invalidate the cache entry for the named module, causing
but it will invalidate the cache entry for the named module, causing
Python to search anew for the named module upon its next
Python to search anew for the named module upon its next
import. The key can also be assigned to ``None``, forcing the next import
import. The key can also be assigned to ``None``, forcing the next import
of the module to result in an :exc:`
ModuleNotFound
Error`.
of the module to result in an :exc:`
Import
Error`.
Beware though, as if you keep a reference to the module object,
Beware though, as if you keep a reference to the module object,
invalidate its cache entry in :data:`sys.modules`, and then re-import the
invalidate its cache entry in :data:`sys.modules`, and then re-import the
...
@@ -284,7 +284,7 @@ handle the named module or not.
...
@@ -284,7 +284,7 @@ handle the named module or not.
If
the
meta
path
finder
knows
how
to
handle
the
named
module
,
it
returns
a
If
the
meta
path
finder
knows
how
to
handle
the
named
module
,
it
returns
a
loader
object
.
If
it
cannot
handle
the
named
module
,
it
returns
``
None
``.
If
loader
object
.
If
it
cannot
handle
the
named
module
,
it
returns
``
None
``.
If
:
data
:`
sys
.
meta_path
`
processing
reaches
the
end
of
its
list
without
returning
:
data
:`
sys
.
meta_path
`
processing
reaches
the
end
of
its
list
without
returning
a
loader
,
then
an
:
exc
:`
ModuleNotFound
Error
`
is
raised
.
Any
other
exceptions
raised
a
loader
,
then
an
:
exc
:`
Import
Error
`
is
raised
.
Any
other
exceptions
raised
are
simply
propagated
up
,
aborting
the
import
process
.
are
simply
propagated
up
,
aborting
the
import
process
.
The
:
meth
:`
find_module
()`
method
of
meta
path
finders
is
called
with
two
The
:
meth
:`
find_module
()`
method
of
meta
path
finders
is
called
with
two
...
@@ -647,7 +647,7 @@ import statements within that module.
...
@@ -647,7 +647,7 @@ import statements within that module.
To
selectively
prevent
import
of
some
modules
from
a
hook
early
on
the
To
selectively
prevent
import
of
some
modules
from
a
hook
early
on
the
meta
path
(
rather
than
disabling
the
standard
import
system
entirely
),
meta
path
(
rather
than
disabling
the
standard
import
system
entirely
),
it
is
sufficient
to
raise
:
exc
:`
ModuleNotFound
Error
`
directly
from
it
is
sufficient
to
raise
:
exc
:`
Import
Error
`
directly
from
:
meth
:`
find_module
`
instead
of
returning
``
None
``.
The
latter
indicates
:
meth
:`
find_module
`
instead
of
returning
``
None
``.
The
latter
indicates
that
the
meta
path
search
should
continue
.
while
raising
an
exception
that
the
meta
path
search
should
continue
.
while
raising
an
exception
terminates
it
immediately
.
terminates
it
immediately
.
...
...
Doc/whatsnew/3.4.rst
View file @
82da8886
...
@@ -312,7 +312,8 @@ that may require changes to your code.
...
@@ -312,7 +312,8 @@ that may require changes to your code.
using ``hasattr(module, '__path__')``.
using ``hasattr(module, '__path__')``.
* :c:func:`PyErr_SetImportError` now sets :exc:`TypeError` when its **msg**
* :c:func:`PyErr_SetImportError` now sets :exc:`TypeError` when its **msg**
argument is not set. Previously only ``NULL`` was returned.
argument is not set. Previously only ``NULL`` was returned with no exception
set.
* :func:`py_compile.compile` now raises :exc:`FileExistsError` if the file path
* :func:`py_compile.compile` now raises :exc:`FileExistsError` if the file path
it would write to is a symlink or a non-regular file. This is to act as a
it would write to is a symlink or a non-regular file. This is to act as a
...
...
Include/pyerrors.h
View file @
82da8886
...
@@ -268,9 +268,6 @@ PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErr(PyObject *, int);
...
@@ -268,9 +268,6 @@ PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErr(PyObject *, int);
PyAPI_FUNC
(
PyObject
*
)
PyErr_SetExcWithArgsKwargs
(
PyObject
*
,
PyObject
*
,
PyAPI_FUNC
(
PyObject
*
)
PyErr_SetExcWithArgsKwargs
(
PyObject
*
,
PyObject
*
,
PyObject
*
);
PyObject
*
);
PyAPI_FUNC
(
PyObject
*
)
PyErr_SetImportErrorSubclass
(
PyObject
*
,
PyObject
*
,
PyObject
*
,
PyObject
*
);
PyAPI_FUNC
(
PyObject
*
)
PyErr_SetImportError
(
PyObject
*
,
PyObject
*
,
PyAPI_FUNC
(
PyObject
*
)
PyErr_SetImportError
(
PyObject
*
,
PyObject
*
,
PyObject
*
);
PyObject
*
);
...
...
Lib/importlib/_bootstrap.py
View file @
82da8886
...
@@ -1617,7 +1617,7 @@ def _gcd_import(name, package=None, level=0):
...
@@ -1617,7 +1617,7 @@ def _gcd_import(name, package=None, level=0):
_imp
.
release_lock
()
_imp
.
release_lock
()
message
=
(
"import of {} halted; "
message
=
(
"import of {} halted; "
"None in sys.modules"
.
format
(
name
))
"None in sys.modules"
.
format
(
name
))
raise
ModuleNotFound
Error
(
message
,
name
=
name
)
raise
Import
Error
(
message
,
name
=
name
)
_lock_unlock_module
(
name
)
_lock_unlock_module
(
name
)
return
module
return
module
...
...
Misc/NEWS
View file @
82da8886
...
@@ -539,10 +539,6 @@ Documentation
...
@@ -539,10 +539,6 @@ Documentation
C
-
API
C
-
API
-----
-----
-
Issue
#
15767
:
Added
PyErr_SetImportErrorSubclass
().
-
PyErr_SetImportError
()
now
sets
TypeError
when
its
msg
argument
is
set
.
-
Issue
#
9369
:
The
types
of
`
char
*`
arguments
of
PyObject_CallFunction
()
and
-
Issue
#
9369
:
The
types
of
`
char
*`
arguments
of
PyObject_CallFunction
()
and
PyObject_CallMethod
()
now
changed
to
`
const
char
*`.
Based
on
patches
by
PyObject_CallMethod
()
now
changed
to
`
const
char
*`.
Based
on
patches
by
J
ö
rg
M
ü
ller
and
Lars
Buitinck
.
J
ö
rg
M
ü
ller
and
Lars
Buitinck
.
...
...
Python/errors.c
View file @
82da8886
...
@@ -619,25 +619,12 @@ PyObject *PyErr_SetFromWindowsErrWithUnicodeFilename(
...
@@ -619,25 +619,12 @@ PyObject *PyErr_SetFromWindowsErrWithUnicodeFilename(
#endif
/* MS_WINDOWS */
#endif
/* MS_WINDOWS */
PyObject
*
PyObject
*
PyErr_SetImportErrorSubclass
(
PyObject
*
exception
,
PyObject
*
msg
,
PyErr_SetImportError
(
PyObject
*
msg
,
PyObject
*
name
,
PyObject
*
path
)
PyObject
*
name
,
PyObject
*
path
)
{
{
int
issubclass
;
PyObject
*
args
,
*
kwargs
,
*
error
;
PyObject
*
args
,
*
kwargs
,
*
error
;
issubclass
=
PyObject_IsSubclass
(
exception
,
PyExc_ImportError
);
if
(
msg
==
NULL
)
if
(
issubclass
<
0
)
{
return
NULL
;
}
else
if
(
!
issubclass
)
{
PyErr_SetString
(
PyExc_TypeError
,
"expected a subclass of ImportError"
);
return
NULL
;
}
if
(
msg
==
NULL
)
{
PyErr_SetString
(
PyExc_TypeError
,
"expected a message argument"
);
return
NULL
;
return
NULL
;
}
args
=
PyTuple_New
(
1
);
args
=
PyTuple_New
(
1
);
if
(
args
==
NULL
)
if
(
args
==
NULL
)
...
@@ -662,7 +649,7 @@ PyErr_SetImportErrorSubclass(PyObject *exception, PyObject *msg,
...
@@ -662,7 +649,7 @@ PyErr_SetImportErrorSubclass(PyObject *exception, PyObject *msg,
PyDict_SetItemString
(
kwargs
,
"name"
,
name
);
PyDict_SetItemString
(
kwargs
,
"name"
,
name
);
PyDict_SetItemString
(
kwargs
,
"path"
,
path
);
PyDict_SetItemString
(
kwargs
,
"path"
,
path
);
error
=
PyObject_Call
(
exception
,
args
,
kwargs
);
error
=
PyObject_Call
(
PyExc_ImportError
,
args
,
kwargs
);
if
(
error
!=
NULL
)
{
if
(
error
!=
NULL
)
{
PyErr_SetObject
((
PyObject
*
)
Py_TYPE
(
error
),
error
);
PyErr_SetObject
((
PyObject
*
)
Py_TYPE
(
error
),
error
);
Py_DECREF
(
error
);
Py_DECREF
(
error
);
...
@@ -674,12 +661,6 @@ PyErr_SetImportErrorSubclass(PyObject *exception, PyObject *msg,
...
@@ -674,12 +661,6 @@ PyErr_SetImportErrorSubclass(PyObject *exception, PyObject *msg,
return
NULL
;
return
NULL
;
}
}
PyObject
*
PyErr_SetImportError
(
PyObject
*
msg
,
PyObject
*
name
,
PyObject
*
path
)
{
return
PyErr_SetImportErrorSubclass
(
PyExc_ImportError
,
msg
,
name
,
path
);
}
void
void
_PyErr_BadInternalCall
(
const
char
*
filename
,
int
lineno
)
_PyErr_BadInternalCall
(
const
char
*
filename
,
int
lineno
)
{
{
...
...
Python/import.c
View file @
82da8886
...
@@ -1428,8 +1428,7 @@ PyImport_ImportModuleLevelObject(PyObject *name, PyObject *given_globals,
...
@@ -1428,8 +1428,7 @@ PyImport_ImportModuleLevelObject(PyObject *name, PyObject *given_globals,
PyObject
*
msg
=
PyUnicode_FromFormat
(
"import of %R halted; "
PyObject
*
msg
=
PyUnicode_FromFormat
(
"import of %R halted; "
"None in sys.modules"
,
abs_name
);
"None in sys.modules"
,
abs_name
);
if
(
msg
!=
NULL
)
{
if
(
msg
!=
NULL
)
{
PyErr_SetImportErrorSubclass
(
PyExc_ModuleNotFoundError
,
msg
,
PyErr_SetImportError
(
msg
,
abs_name
,
NULL
);
abs_name
,
NULL
);
Py_DECREF
(
msg
);
Py_DECREF
(
msg
);
}
}
mod
=
NULL
;
mod
=
NULL
;
...
...
Python/importlib.h
View file @
82da8886
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment