mirror of
https://github.com/python/cpython.git
synced 2025-07-29 14:15:07 +00:00
Add Py3k warnings to os.path.walk
This commit is contained in:
parent
9ec4aa01f9
commit
0893a0a961
6 changed files with 23 additions and 6 deletions
|
@ -303,10 +303,10 @@ write files see :func:`open`, and for accessing the filesystem see the
|
||||||
identify them with ``os.path.islink(file)`` and ``os.path.isdir(file)``, and
|
identify them with ``os.path.islink(file)`` and ``os.path.isdir(file)``, and
|
||||||
invoke :func:`walk` as necessary.
|
invoke :func:`walk` as necessary.
|
||||||
|
|
||||||
.. note::
|
.. warning::
|
||||||
|
|
||||||
The newer :func:`os.walk` :term:`generator` supplies similar functionality
|
This function is deprecated and is removed in 3.0 in favor of
|
||||||
and can be easier to use.
|
:func:`os.walk`.
|
||||||
|
|
||||||
|
|
||||||
.. data:: supports_unicode_filenames
|
.. data:: supports_unicode_filenames
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
"""Pathname and path-related operations for the Macintosh."""
|
"""Pathname and path-related operations for the Macintosh."""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import warnings
|
||||||
from stat import *
|
from stat import *
|
||||||
import genericpath
|
import genericpath
|
||||||
from genericpath import *
|
from genericpath import *
|
||||||
|
@ -169,7 +170,7 @@ def walk(top, func, arg):
|
||||||
beyond that arg is always passed to func. It can be used, e.g., to pass
|
beyond that arg is always passed to func. It can be used, e.g., to pass
|
||||||
a filename pattern, or a mutable object designed to accumulate
|
a filename pattern, or a mutable object designed to accumulate
|
||||||
statistics. Passing None for arg is common."""
|
statistics. Passing None for arg is common."""
|
||||||
|
warnings.warnpy3k("In 3.x, os.path.walk is removed in favor of os.walk.")
|
||||||
try:
|
try:
|
||||||
names = os.listdir(top)
|
names = os.listdir(top)
|
||||||
except os.error:
|
except os.error:
|
||||||
|
|
|
@ -9,6 +9,8 @@ import os
|
||||||
import sys
|
import sys
|
||||||
import stat
|
import stat
|
||||||
import genericpath
|
import genericpath
|
||||||
|
import warnings
|
||||||
|
|
||||||
from genericpath import *
|
from genericpath import *
|
||||||
|
|
||||||
__all__ = ["normcase","isabs","join","splitdrive","split","splitext",
|
__all__ = ["normcase","isabs","join","splitdrive","split","splitext",
|
||||||
|
@ -248,7 +250,7 @@ def walk(top, func, arg):
|
||||||
beyond that arg is always passed to func. It can be used, e.g., to pass
|
beyond that arg is always passed to func. It can be used, e.g., to pass
|
||||||
a filename pattern, or a mutable object designed to accumulate
|
a filename pattern, or a mutable object designed to accumulate
|
||||||
statistics. Passing None for arg is common."""
|
statistics. Passing None for arg is common."""
|
||||||
|
warnings.warnpy3k("In 3.x, os.path.walk is removed in favor of os.walk.")
|
||||||
try:
|
try:
|
||||||
names = os.listdir(top)
|
names = os.listdir(top)
|
||||||
except os.error:
|
except os.error:
|
||||||
|
|
|
@ -13,6 +13,7 @@ for manipulation of the pathname component of URLs.
|
||||||
import os
|
import os
|
||||||
import stat
|
import stat
|
||||||
import genericpath
|
import genericpath
|
||||||
|
import warnings
|
||||||
from genericpath import *
|
from genericpath import *
|
||||||
|
|
||||||
__all__ = ["normcase","isabs","join","splitdrive","split","splitext",
|
__all__ = ["normcase","isabs","join","splitdrive","split","splitext",
|
||||||
|
@ -215,7 +216,7 @@ def walk(top, func, arg):
|
||||||
beyond that arg is always passed to func. It can be used, e.g., to pass
|
beyond that arg is always passed to func. It can be used, e.g., to pass
|
||||||
a filename pattern, or a mutable object designed to accumulate
|
a filename pattern, or a mutable object designed to accumulate
|
||||||
statistics. Passing None for arg is common."""
|
statistics. Passing None for arg is common."""
|
||||||
|
warnings.warnpy3k("In 3.x, os.path.walk is removed in favor of os.walk.")
|
||||||
try:
|
try:
|
||||||
names = os.listdir(top)
|
names = os.listdir(top)
|
||||||
except os.error:
|
except os.error:
|
||||||
|
|
|
@ -157,6 +157,17 @@ class TestStdlibRemovals(unittest.TestCase):
|
||||||
for module_name in self.all_platforms:
|
for module_name in self.all_platforms:
|
||||||
self.check_removal(module_name)
|
self.check_removal(module_name)
|
||||||
|
|
||||||
|
def test_os_path_walk(self):
|
||||||
|
msg = "In 3.x, os.path.walk is removed in favor of os.walk."
|
||||||
|
def dumbo(where, names, args): pass
|
||||||
|
for path_mod in ("ntpath", "macpath", "os2emxpath", "posixpath"):
|
||||||
|
mod = __import__(path_mod)
|
||||||
|
with catch_warning() as w:
|
||||||
|
# Since os3exmpath just imports it from ntpath
|
||||||
|
warnings.simplefilter("always")
|
||||||
|
mod.walk(".", dumbo, None)
|
||||||
|
self.assertEquals(str(w.message), msg)
|
||||||
|
|
||||||
|
|
||||||
def test_main():
|
def test_main():
|
||||||
run_unittest(TestPy3KWarnings, TestStdlibRemovals)
|
run_unittest(TestPy3KWarnings, TestStdlibRemovals)
|
||||||
|
|
|
@ -30,6 +30,8 @@ Library
|
||||||
|
|
||||||
- test.test_support.catch_warning() gained a 'record' argument.
|
- test.test_support.catch_warning() gained a 'record' argument.
|
||||||
|
|
||||||
|
- os.path.walk is deprecated in favor of os.walk.
|
||||||
|
|
||||||
Build
|
Build
|
||||||
-----
|
-----
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue