summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorChristian Heimes <christian@cheimes.de>2007-11-27 21:50:00 (GMT)
committerChristian Heimes <christian@cheimes.de>2007-11-27 21:50:00 (GMT)
commit45f9af34b334b483678225a943578d2e1ea540b1 (patch)
tree07d42daf6094f704adb5b4322891601e91176ada /Lib
parent1c280ab7d62b4ae420964b655d99a8e4186320b3 (diff)
downloadcpython-45f9af34b334b483678225a943578d2e1ea540b1.zip
cpython-45f9af34b334b483678225a943578d2e1ea540b1.tar.gz
cpython-45f9af34b334b483678225a943578d2e1ea540b1.tar.bz2
Merged revisions 59193-59201 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r59195 | facundo.batista | 2007-11-27 19:50:12 +0100 (Tue, 27 Nov 2007) | 4 lines Moved the errno import from inside the functions to the module level. Fixes issue 1755179. ........ r59199 | christian.heimes | 2007-11-27 22:28:40 +0100 (Tue, 27 Nov 2007) | 1 line Backport of changes to PCbuild9 from the py3k branch ........ r59200 | christian.heimes | 2007-11-27 22:34:01 +0100 (Tue, 27 Nov 2007) | 1 line Replaced import of the 'new' module with 'types' module and added a deprecation warning to the 'new' module. ........ r59201 | christian.heimes | 2007-11-27 22:35:44 +0100 (Tue, 27 Nov 2007) | 1 line Added a deprecation warning to the 'new' module. ........
Diffstat (limited to 'Lib')
-rw-r--r--Lib/doctest.py8
-rw-r--r--Lib/modulefinder.py4
-rw-r--r--Lib/new.py3
-rw-r--r--Lib/os.py9
-rw-r--r--Lib/test/test_descr.py1
-rw-r--r--Lib/test/test_doctest.py14
-rw-r--r--Lib/test/test_funcattrs.py4
-rw-r--r--Lib/test/test_getopt.py4
-rw-r--r--Lib/test/test_inspect.py4
-rw-r--r--Lib/test/test_unittest.py88
10 files changed, 55 insertions, 84 deletions
diff --git a/Lib/doctest.py b/Lib/doctest.py
index f135027..eb863cb 100644
--- a/Lib/doctest.py
+++ b/Lib/doctest.py
@@ -2010,16 +2010,16 @@ class Tester:
return (f,t)
def rundict(self, d, name, module=None):
- import new
- m = new.module(name)
+ import types
+ m = types.ModuleType(name)
m.__dict__.update(d)
if module is None:
module = False
return self.rundoc(m, name, module)
def run__test__(self, d, name):
- import new
- m = new.module(name)
+ import types
+ m = types.ModuleType(name)
m.__test__ = d
return self.rundoc(m, name)
diff --git a/Lib/modulefinder.py b/Lib/modulefinder.py
index c345a33..e4184a1 100644
--- a/Lib/modulefinder.py
+++ b/Lib/modulefinder.py
@@ -7,7 +7,7 @@ import imp
import marshal
import os
import sys
-import new
+import types
import struct
if hasattr(sys.__stdout__, "newlines"):
@@ -589,7 +589,7 @@ class ModuleFinder:
if isinstance(consts[i], type(co)):
consts[i] = self.replace_paths_in_code(consts[i])
- return new.code(co.co_argcount, co.co_nlocals, co.co_stacksize,
+ return types.CodeType(co.co_argcount, co.co_nlocals, co.co_stacksize,
co.co_flags, co.co_code, tuple(consts), co.co_names,
co.co_varnames, new_filename, co.co_name,
co.co_firstlineno, co.co_lnotab,
diff --git a/Lib/new.py b/Lib/new.py
index e6079c2..6ce9a55 100644
--- a/Lib/new.py
+++ b/Lib/new.py
@@ -3,6 +3,9 @@
This module is no longer required except for backward compatibility.
Objects of most types can now be created by calling the type object.
"""
+from warnings import warn as _warn
+_warn("The 'new' module is not supported in 3.x, use the 'types' module "
+ "instead.", DeprecationWarning, 2)
classobj = type
from types import FunctionType as function
diff --git a/Lib/os.py b/Lib/os.py
index 451f833..82b4027 100644
--- a/Lib/os.py
+++ b/Lib/os.py
@@ -22,7 +22,7 @@ and opendir), and leave all pathname manipulation to os.path
#'
-import sys
+import sys, errno
_names = sys.builtin_module_names
@@ -140,7 +140,6 @@ def makedirs(name, mode=0o777):
recursive.
"""
- from errno import EEXIST
head, tail = path.split(name)
if not tail:
head, tail = path.split(head)
@@ -149,7 +148,7 @@ def makedirs(name, mode=0o777):
makedirs(head, mode)
except OSError as e:
# be happy if someone already created the path
- if e.errno != EEXIST:
+ if e.errno != errno.EEXIST:
raise
if tail == curdir: # xxx/newdir/. exists if xxx/newdir exists
return
@@ -353,8 +352,6 @@ def execvpe(file, args, env):
__all__.extend(["execl","execle","execlp","execlpe","execvp","execvpe"])
def _execvpe(file, args, env=None):
- from errno import ENOENT, ENOTDIR
-
if env is not None:
func = execve
argrest = (args, env)
@@ -381,7 +378,7 @@ def _execvpe(file, args, env=None):
except error as e:
last_exc = e
tb = sys.exc_info()[2]
- if (e.errno != ENOENT and e.errno != ENOTDIR
+ if (e.errno != errno.ENOENT and e.errno != errno.ENOTDIR
and saved_exc is None):
saved_exc = e
saved_tb = tb
diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py
index a518f16..aa01805 100644
--- a/Lib/test/test_descr.py
+++ b/Lib/test/test_descr.py
@@ -4,7 +4,6 @@ from test.test_support import verify, vereq, verbose, TestFailed, TESTFN
from test.test_support import get_original_stdout
from copy import deepcopy
import types
-import new
def veris(a, b):
if a is not b:
diff --git a/Lib/test/test_doctest.py b/Lib/test/test_doctest.py
index 02034b4..6ebfb69 100644
--- a/Lib/test/test_doctest.py
+++ b/Lib/test/test_doctest.py
@@ -448,8 +448,8 @@ docstring, and will recursively explore its contents, including
functions, classes, and the `__test__` dictionary, if it exists:
>>> # A module
- >>> import new
- >>> m = new.module('some_module')
+ >>> import types
+ >>> m = types.ModuleType('some_module')
>>> def triple(val):
... '''
... >>> print(triple(11))
@@ -1941,11 +1941,11 @@ def test_DocFileSuite():
If DocFileSuite is used from an interactive session, then files
are resolved relative to the directory of sys.argv[0]:
- >>> import new, os.path, test.test_doctest
+ >>> import types, os.path, test.test_doctest
>>> save_argv = sys.argv
>>> sys.argv = [test.test_doctest.__file__]
>>> suite = doctest.DocFileSuite('test_doctest.txt',
- ... package=new.module('__main__'))
+ ... package=types.ModuleType('__main__'))
>>> sys.argv = save_argv
By setting `module_relative=False`, os-specific paths may be
@@ -2370,9 +2370,9 @@ def old_test3(): r"""
"""
def old_test4(): """
- >>> import new
- >>> m1 = new.module('_m1')
- >>> m2 = new.module('_m2')
+ >>> import types
+ >>> m1 = types.ModuleType('_m1')
+ >>> m2 = types.ModuleType('_m2')
>>> test_data = \"""
... def _f():
... '''>>> assert 1 == 1
diff --git a/Lib/test/test_funcattrs.py b/Lib/test/test_funcattrs.py
index 3d0d4aa..1a62290 100644
--- a/Lib/test/test_funcattrs.py
+++ b/Lib/test/test_funcattrs.py
@@ -105,11 +105,11 @@ if f2.a.one != f1.a.one != F.a.one != 11:
raise TestFailed
# __func__ may not be a Python method!
-import new
+import types
F.id = id
eff = F()
-eff.id = new.instancemethod(id, eff)
+eff.id = types.MethodType(id, eff)
if eff.id() != id(eff):
raise TestFailed
diff --git a/Lib/test/test_getopt.py b/Lib/test/test_getopt.py
index a3a9940..36d1688 100644
--- a/Lib/test/test_getopt.py
+++ b/Lib/test/test_getopt.py
@@ -167,8 +167,8 @@ class GetoptTests(unittest.TestCase):
['a1', 'a2']
"""
- import new
- m = new.module("libreftest", s)
+ import types
+ m = types.ModuleType("libreftest", s)
run_doctest(m, verbose)
diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py
index 3752810..4b78708 100644
--- a/Lib/test/test_inspect.py
+++ b/Lib/test/test_inspect.py
@@ -213,9 +213,9 @@ class TestRetrievingSourceCode(GetSourceBase):
self.assertEqual(inspect.getfile(mod.StupidGit), mod.__file__)
def test_getmodule_recursion(self):
- from new import module
+ from types import ModuleType
name = '__inspect_dummy'
- m = sys.modules[name] = module(name)
+ m = sys.modules[name] = ModuleType(name)
m.__file__ = "<string>" # hopefully not a real filename...
m.__loader__ = "dummy" # pretend the filename is understood by a loader
exec("def x(): pass", m.__dict__)
diff --git a/Lib/test/test_unittest.py b/Lib/test/test_unittest.py
index eac8074..ed27618 100644
--- a/Lib/test/test_unittest.py
+++ b/Lib/test/test_unittest.py
@@ -9,6 +9,7 @@ Still need testing:
from test import test_support
import unittest
from unittest import TestCase
+import types
### Support code
################################################################
@@ -153,8 +154,7 @@ class Test_TestLoader(TestCase):
# "This method searches `module` for classes derived from TestCase"
def test_loadTestsFromModule__TestCase_subclass(self):
- import new
- m = new.module('m')
+ m = types.ModuleType('m')
class MyTestCase(unittest.TestCase):
def test(self):
pass
@@ -171,8 +171,7 @@ class Test_TestLoader(TestCase):
#
# What happens if no tests are found (no TestCase instances)?
def test_loadTestsFromModule__no_TestCase_instances(self):
- import new
- m = new.module('m')
+ m = types.ModuleType('m')
loader = unittest.TestLoader()
suite = loader.loadTestsFromModule(m)
@@ -183,8 +182,7 @@ class Test_TestLoader(TestCase):
#
# What happens if no tests are found (TestCases instances, but no tests)?
def test_loadTestsFromModule__no_TestCase_tests(self):
- import new
- m = new.module('m')
+ m = types.ModuleType('m')
class MyTestCase(unittest.TestCase):
pass
m.testcase_1 = MyTestCase
@@ -381,8 +379,7 @@ class Test_TestLoader(TestCase):
# Does it raise an exception if the name resolves to an invalid
# object?
def test_loadTestsFromName__relative_bad_object(self):
- import new
- m = new.module('m')
+ m = types.ModuleType('m')
m.testcase_1 = object()
loader = unittest.TestLoader()
@@ -396,8 +393,7 @@ class Test_TestLoader(TestCase):
# "The specifier name is a ``dotted name'' that may
# resolve either to ... a test case class"
def test_loadTestsFromName__relative_TestCase_subclass(self):
- import new
- m = new.module('m')
+ m = types.ModuleType('m')
class MyTestCase(unittest.TestCase):
def test(self):
pass
@@ -413,8 +409,7 @@ class Test_TestLoader(TestCase):
# within a test case class, or a callable object which returns a
# TestCase or TestSuite instance."
def test_loadTestsFromName__relative_TestSuite(self):
- import new
- m = new.module('m')
+ m = types.ModuleType('m')
class MyTestCase(unittest.TestCase):
def test(self):
pass
@@ -429,8 +424,7 @@ class Test_TestLoader(TestCase):
# "The specifier name is a ``dotted name'' that may resolve ... to
# ... a test method within a test case class"
def test_loadTestsFromName__relative_testmethod(self):
- import new
- m = new.module('m')
+ m = types.ModuleType('m')
class MyTestCase(unittest.TestCase):
def test(self):
pass
@@ -451,8 +445,7 @@ class Test_TestLoader(TestCase):
# resolve "a test method within a test case class" that doesn't exist
# for the given name (relative to a provided module)?
def test_loadTestsFromName__relative_invalid_testmethod(self):
- import new
- m = new.module('m')
+ m = types.ModuleType('m')
class MyTestCase(unittest.TestCase):
def test(self):
pass
@@ -469,8 +462,7 @@ class Test_TestLoader(TestCase):
# "The specifier name is a ``dotted name'' that may resolve ... to
# ... a callable object which returns a ... TestSuite instance"
def test_loadTestsFromName__callable__TestSuite(self):
- import new
- m = new.module('m')
+ m = types.ModuleType('m')
testcase_1 = unittest.FunctionTestCase(lambda: None)
testcase_2 = unittest.FunctionTestCase(lambda: None)
def return_TestSuite():
@@ -485,8 +477,7 @@ class Test_TestLoader(TestCase):
# "The specifier name is a ``dotted name'' that may resolve ... to
# ... a callable object which returns a TestCase ... instance"
def test_loadTestsFromName__callable__TestCase_instance(self):
- import new
- m = new.module('m')
+ m = types.ModuleType('m')
testcase_1 = unittest.FunctionTestCase(lambda: None)
def return_TestCase():
return testcase_1
@@ -502,8 +493,7 @@ class Test_TestLoader(TestCase):
#
# What happens if the callable returns something else?
def test_loadTestsFromName__callable__wrong_type(self):
- import new
- m = new.module('m')
+ m = types.ModuleType('m')
def return_wrong():
return 6
m.return_wrong = return_wrong
@@ -751,8 +741,7 @@ class Test_TestLoader(TestCase):
# Does it raise an exception if the name resolves to an invalid
# object?
def test_loadTestsFromNames__relative_bad_object(self):
- import new
- m = new.module('m')
+ m = types.ModuleType('m')
m.testcase_1 = object()
loader = unittest.TestLoader()
@@ -766,8 +755,7 @@ class Test_TestLoader(TestCase):
# "The specifier name is a ``dotted name'' that may resolve ... to
# ... a test case class"
def test_loadTestsFromNames__relative_TestCase_subclass(self):
- import new
- m = new.module('m')
+ m = types.ModuleType('m')
class MyTestCase(unittest.TestCase):
def test(self):
pass
@@ -783,8 +771,7 @@ class Test_TestLoader(TestCase):
# "The specifier name is a ``dotted name'' that may resolve ... to
# ... a TestSuite instance"
def test_loadTestsFromNames__relative_TestSuite(self):
- import new
- m = new.module('m')
+ m = types.ModuleType('m')
class MyTestCase(unittest.TestCase):
def test(self):
pass
@@ -799,8 +786,7 @@ class Test_TestLoader(TestCase):
# "The specifier name is a ``dotted name'' that may resolve ... to ... a
# test method within a test case class"
def test_loadTestsFromNames__relative_testmethod(self):
- import new
- m = new.module('m')
+ m = types.ModuleType('m')
class MyTestCase(unittest.TestCase):
def test(self):
pass
@@ -819,8 +805,7 @@ class Test_TestLoader(TestCase):
# Does the method gracefully handle names that initially look like they
# resolve to "a test method within a test case class" but don't?
def test_loadTestsFromNames__relative_invalid_testmethod(self):
- import new
- m = new.module('m')
+ m = types.ModuleType('m')
class MyTestCase(unittest.TestCase):
def test(self):
pass
@@ -837,8 +822,7 @@ class Test_TestLoader(TestCase):
# "The specifier name is a ``dotted name'' that may resolve ... to
# ... a callable object which returns a ... TestSuite instance"
def test_loadTestsFromNames__callable__TestSuite(self):
- import new
- m = new.module('m')
+ m = types.ModuleType('m')
testcase_1 = unittest.FunctionTestCase(lambda: None)
testcase_2 = unittest.FunctionTestCase(lambda: None)
def return_TestSuite():
@@ -855,8 +839,7 @@ class Test_TestLoader(TestCase):
# "The specifier name is a ``dotted name'' that may resolve ... to
# ... a callable object which returns a TestCase ... instance"
def test_loadTestsFromNames__callable__TestCase_instance(self):
- import new
- m = new.module('m')
+ m = types.ModuleType('m')
testcase_1 = unittest.FunctionTestCase(lambda: None)
def return_TestCase():
return testcase_1
@@ -874,8 +857,7 @@ class Test_TestLoader(TestCase):
#
# Are staticmethods handled correctly?
def test_loadTestsFromNames__callable__call_staticmethod(self):
- import new
- m = new.module('m')
+ m = types.ModuleType('m')
class Test1(unittest.TestCase):
def test(self):
pass
@@ -899,8 +881,7 @@ class Test_TestLoader(TestCase):
#
# What happens when the callable returns something else?
def test_loadTestsFromNames__callable__wrong_type(self):
- import new
- m = new.module('m')
+ m = types.ModuleType('m')
def return_wrong():
return 6
m.return_wrong = return_wrong
@@ -1043,8 +1024,7 @@ class Test_TestLoader(TestCase):
# Implicit in the documentation is that testMethodPrefix is respected by
# all loadTestsFrom* methods.
def test_testMethodPrefix__loadTestsFromModule(self):
- import new
- m = new.module('m')
+ m = types.ModuleType('m')
class Foo(unittest.TestCase):
def test_1(self): pass
def test_2(self): pass
@@ -1067,8 +1047,7 @@ class Test_TestLoader(TestCase):
# Implicit in the documentation is that testMethodPrefix is respected by
# all loadTestsFrom* methods.
def test_testMethodPrefix__loadTestsFromName(self):
- import new
- m = new.module('m')
+ m = types.ModuleType('m')
class Foo(unittest.TestCase):
def test_1(self): pass
def test_2(self): pass
@@ -1091,8 +1070,7 @@ class Test_TestLoader(TestCase):
# Implicit in the documentation is that testMethodPrefix is respected by
# all loadTestsFrom* methods.
def test_testMethodPrefix__loadTestsFromNames(self):
- import new
- m = new.module('m')
+ m = types.ModuleType('m')
class Foo(unittest.TestCase):
def test_1(self): pass
def test_2(self): pass
@@ -1143,8 +1121,7 @@ class Test_TestLoader(TestCase):
def reversed_cmp(x, y):
return -cmp(x, y)
- import new
- m = new.module('m')
+ m = types.ModuleType('m')
class Foo(unittest.TestCase):
def test_1(self): pass
def test_2(self): pass
@@ -1162,8 +1139,7 @@ class Test_TestLoader(TestCase):
def reversed_cmp(x, y):
return -cmp(x, y)
- import new
- m = new.module('m')
+ m = types.ModuleType('m')
class Foo(unittest.TestCase):
def test_1(self): pass
def test_2(self): pass
@@ -1181,8 +1157,7 @@ class Test_TestLoader(TestCase):
def reversed_cmp(x, y):
return -cmp(x, y)
- import new
- m = new.module('m')
+ m = types.ModuleType('m')
class Foo(unittest.TestCase):
def test_1(self): pass
def test_2(self): pass
@@ -1254,8 +1229,7 @@ class Test_TestLoader(TestCase):
# It is implicit in the documentation for TestLoader.suiteClass that
# all TestLoader.loadTestsFrom* methods respect it. Let's make sure
def test_suiteClass__loadTestsFromModule(self):
- import new
- m = new.module('m')
+ m = types.ModuleType('m')
class Foo(unittest.TestCase):
def test_1(self): pass
def test_2(self): pass
@@ -1271,8 +1245,7 @@ class Test_TestLoader(TestCase):
# It is implicit in the documentation for TestLoader.suiteClass that
# all TestLoader.loadTestsFrom* methods respect it. Let's make sure
def test_suiteClass__loadTestsFromName(self):
- import new
- m = new.module('m')
+ m = types.ModuleType('m')
class Foo(unittest.TestCase):
def test_1(self): pass
def test_2(self): pass
@@ -1288,8 +1261,7 @@ class Test_TestLoader(TestCase):
# It is implicit in the documentation for TestLoader.suiteClass that
# all TestLoader.loadTestsFrom* methods respect it. Let's make sure
def test_suiteClass__loadTestsFromNames(self):
- import new
- m = new.module('m')
+ m = types.ModuleType('m')
class Foo(unittest.TestCase):
def test_1(self): pass
def test_2(self): pass