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
1d4601c2
Commit
1d4601c2
authored
Feb 15, 2017
by
Matthias Bussonnier
Committed by
Brett Cannon
Feb 15, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-29576: add explicit deprecation for importlib.abc.find_loader() and find_module() (GH-32)
parent
72dccde8
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
41 additions
and
7 deletions
+41
-7
Doc/whatsnew/3.7.rst
Doc/whatsnew/3.7.rst
+11
-0
Lib/importlib/__init__.py
Lib/importlib/__init__.py
+2
-1
Lib/importlib/abc.py
Lib/importlib/abc.py
+19
-6
Lib/test/test_importlib/test_abc.py
Lib/test/test_importlib/test_abc.py
+6
-0
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Doc/whatsnew/3.7.rst
View file @
1d4601c2
...
...
@@ -140,6 +140,17 @@ Deprecated
``0x03050400`` and ``0x03060000`` (not including) or ``0x03060100`` or
higher. (Contributed by Serhiy Storchaka in :issue:`27867`.)
- Methods
:meth:`MetaPathFinder.find_module() <importlib.abc.MetaPathFinder.find_module>`
(replaced by
:meth:`MetaPathFinder.find_spec() <importlib.abc.MetaPathFinder.find_spec>`
) and
:meth:`PathEntryFinder.find_loader() <importlib.abc.PathEntryFinder.find_loader>`
(replaced by
:meth:`PathEntryFinder.find_spec() <importlib.abc.PathEntryFinder.find_spec>`)
both deprecated in Python 3.4 now emit :exc:`DeprecationWarning`. (Contributed
by Matthias Bussonnier in :issue:`29576`)
Removed
=======
...
...
Lib/importlib/__init__.py
View file @
1d4601c2
...
...
@@ -79,7 +79,8 @@ def find_loader(name, path=None):
This function is deprecated in favor of importlib.util.find_spec().
"""
warnings
.
warn
(
'Use importlib.util.find_spec() instead.'
,
warnings
.
warn
(
'Deprecated since Python 3.4. '
'Use importlib.util.find_spec() instead.'
,
DeprecationWarning
,
stacklevel
=
2
)
try
:
loader
=
sys
.
modules
[
name
].
__loader__
...
...
Lib/importlib/abc.py
View file @
1d4601c2
...
...
@@ -13,6 +13,7 @@ try:
except
ImportError
as
exc
:
_frozen_importlib_external
=
_bootstrap_external
import
abc
import
warnings
def
_register
(
abstract_cls
,
*
classes
):
...
...
@@ -34,6 +35,8 @@ class Finder(metaclass=abc.ABCMeta):
reimplementations of the import system. Otherwise, finder
implementations should derive from the more specific MetaPathFinder
or PathEntryFinder ABCs.
Deprecated since Python 3.3
"""
@
abc
.
abstractmethod
...
...
@@ -57,11 +60,16 @@ class MetaPathFinder(Finder):
If no module is found, return None. The fullname is a str and
the path is a list of strings or None.
This method is deprecated
in favor of finder.find_spec(). If find_spec()
exists then backwards-compatible functionality is provided for this
method.
This method is deprecated
since Python 3.4 in favor of
finder.find_spec(). If find_spec() exists then backwards-compatible
functionality is provided for this
method.
"""
warnings
.
warn
(
"MetaPathFinder.find_module() is deprecated since Python "
"3.4 in favor of MetaPathFinder.find_spec()"
"(available since 3.4)"
,
DeprecationWarning
,
stacklevel
=
2
)
if
not
hasattr
(
self
,
'find_spec'
):
return
None
found
=
self
.
find_spec
(
fullname
,
path
)
...
...
@@ -94,10 +102,15 @@ class PathEntryFinder(Finder):
The portion will be discarded if another path entry finder
locates the module as a normal module or package.
This method is deprecated
in favor of finder.find_spec(). If find_spec()
is provided than backwards-compatible functionality is provided.
This method is deprecated
since Python 3.4 in favor of
finder.find_spec(). If find_spec() is provided than backwards-compatible
functionality is provided.
"""
warnings
.
warn
(
"PathEntryFinder.find_loader() is deprecated since Python "
"3.4 in favor of PathEntryFinder.find_spec() "
"(available since 3.4)"
,
DeprecationWarning
,
stacklevel
=
2
)
if
not
hasattr
(
self
,
'find_spec'
):
return
None
,
[]
found
=
self
.
find_spec
(
fullname
)
...
...
Lib/test/test_importlib/test_abc.py
View file @
1d4601c2
...
...
@@ -163,6 +163,9 @@ class MetaPathFinderDefaultsTests(ABCTestHarness):
# Calling the method is a no-op.
self
.
ins
.
invalidate_caches
()
def
test_find_module_warns
(
self
):
with
self
.
assertWarns
(
DeprecationWarning
):
self
.
ins
.
find_module
(
'something'
,
None
)
(
Frozen_MPFDefaultTests
,
Source_MPFDefaultTests
...
...
@@ -189,6 +192,9 @@ class PathEntryFinderDefaultsTests(ABCTestHarness):
# Should be a no-op.
self
.
ins
.
invalidate_caches
()
def
test_find_loader_warns
(
self
):
with
self
.
assertWarns
(
DeprecationWarning
):
self
.
ins
.
find_loader
(
'something'
)
(
Frozen_PEFDefaultTests
,
Source_PEFDefaultTests
...
...
Misc/NEWS
View file @
1d4601c2
...
...
@@ -229,6 +229,9 @@ Extension Modules
Library
-------
-
bpo
-
29576
:
Improve
some
deprecations
in
importlib
.
Some
deprecated
methods
now
emit
DeprecationWarnings
and
have
better
descriptive
messages
.
-
bpo
-
29534
:
Fixed
different
behaviour
of
Decimal
.
from_float
()
for
_decimal
and
_pydecimal
.
Thanks
Andrew
Nester
.
...
...
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