Kaydet (Commit) 0893a0a9 authored tarafından Benjamin Peterson's avatar Benjamin Peterson

Add Py3k warnings to os.path.walk

üst 9ec4aa01
...@@ -303,10 +303,10 @@ write files see :func:`open`, and for accessing the filesystem see the ...@@ -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
......
"""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): ...@@ -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 ...@@ -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): ...@@ -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. ...@@ -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): ...@@ -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): ...@@ -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 ...@@ -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
----- -----
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment