Kaydet (Commit) c756d00c authored tarafından Christian Heimes's avatar Christian Heimes

Replaced import of the 'new' module with 'types' module and added a deprecation…

Replaced import of the 'new' module with 'types' module and added a deprecation warning to the 'new' module.
üst 8b01140d
"""Support Eiffel-style preconditions and postconditions."""
from new import function
from types import FunctionType as function
class EiffelBaseMetaClass(type):
......
"""A flow graph representation for Python bytecode"""
import dis
import new
import types
import sys
from compiler import misc
......@@ -595,7 +595,7 @@ class PyFlowGraph(FlowGraph):
argcount = self.argcount
if self.flags & CO_VARKEYWORDS:
argcount = argcount - 1
return new.code(argcount, nlocals, self.stacksize, self.flags,
return types.CodeType(argcount, nlocals, self.stacksize, self.flags,
self.lnotab.getCode(), self.getConsts(),
tuple(self.names), tuple(self.varnames),
self.filename, self.name, self.lnotab.firstline,
......
......@@ -2016,16 +2016,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)
......
......@@ -7,7 +7,7 @@ import imp
import marshal
import os
import sys
import new
import types
import struct
if hasattr(sys.__stdout__, "newlines"):
......@@ -594,7 +594,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,
......
......@@ -4,7 +4,6 @@ from test.test_support import verify, vereq, verbose, TestFailed, TESTFN, get_or
from copy import deepcopy
import warnings
import types
import new
warnings.filterwarnings("ignore",
r'complex divmod\(\), // and % are deprecated$',
......
......@@ -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)
......@@ -1937,11 +1937,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
......@@ -2366,9 +2366,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
......
......@@ -132,8 +132,8 @@ if f2.a.one <> f1.a.one <> F.a.one <> 11:
raise TestFailed
# im_func may not be a Python method!
import new
F.id = new.instancemethod(id, None, F)
import types
F.id = types.MethodType(id, None, F)
eff = F()
if eff.id() <> id(eff):
......
......@@ -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)
......
......@@ -203,9 +203,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" in m.__dict__
......
This diff is collapsed.
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