Skip to content

Commit 7f46178

Browse files
deprecate py.std and remove all uses from the own codebase/unrelated tests
1 parent 8d32f8c commit 7f46178

26 files changed

+159
-92
lines changed

py/_code/_assertionold.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import sys, inspect
33
from compiler import parse, ast, pycodegen
44
from py._code.assertion import BuiltinAssertionError, _format_explanation
5+
import types
56

67
passthroughex = py.builtin._sysex
78

@@ -470,7 +471,7 @@ def check(s, frame=None):
470471
def interpret(source, frame, should_fail=False):
471472
module = Interpretable(parse(source, 'exec').node)
472473
#print "got module", module
473-
if isinstance(frame, py.std.types.FrameType):
474+
if isinstance(frame, types.FrameType):
474475
frame = py.code.Frame(frame)
475476
try:
476477
module.run(frame)

py/_code/code.py

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import py
22
import sys
3-
from inspect import CO_VARARGS, CO_VARKEYWORDS
3+
from inspect import CO_VARARGS, CO_VARKEYWORDS, isclass
44

55
builtin_repr = repr
66

@@ -11,6 +11,9 @@
1111
else:
1212
from py._code._py2traceback import format_exception_only
1313

14+
import traceback
15+
16+
1417
class Code(object):
1518
""" wrapper around Python code objects """
1619
def __init__(self, rawcode):
@@ -21,7 +24,7 @@ def __init__(self, rawcode):
2124
self.firstlineno = rawcode.co_firstlineno - 1
2225
self.name = rawcode.co_name
2326
except AttributeError:
24-
raise TypeError("not a code object: %r" %(rawcode,))
27+
raise TypeError("not a code object: %r" % (rawcode,))
2528
self.raw = rawcode
2629

2730
def __eq__(self, other):
@@ -106,7 +109,7 @@ def exec_(self, code, **vars):
106109
"""
107110
f_locals = self.f_locals.copy()
108111
f_locals.update(vars)
109-
py.builtin.exec_(code, self.f_globals, f_locals )
112+
py.builtin.exec_(code, self.f_globals, f_locals)
110113

111114
def repr(self, object):
112115
""" return a 'safe' (non-recursive, one-line) string repr for 'object'
@@ -130,6 +133,7 @@ def getargs(self, var=False):
130133
pass # this can occur when using Psyco
131134
return retval
132135

136+
133137
class TracebackEntry(object):
134138
""" a single entry in a traceback """
135139

@@ -153,7 +157,7 @@ def relline(self):
153157
return self.lineno - self.frame.code.firstlineno
154158

155159
def __repr__(self):
156-
return "<TracebackEntry %s:%d>" %(self.frame.code.path, self.lineno+1)
160+
return "<TracebackEntry %s:%d>" % (self.frame.code.path, self.lineno+1)
157161

158162
@property
159163
def statement(self):
@@ -237,17 +241,19 @@ def __str__(self):
237241
raise
238242
except:
239243
line = "???"
240-
return " File %r:%d in %s\n %s\n" %(fn, self.lineno+1, name, line)
244+
return " File %r:%d in %s\n %s\n" % (fn, self.lineno+1, name, line)
241245

242246
def name(self):
243247
return self.frame.code.raw.co_name
244248
name = property(name, None, None, "co_name of underlaying code")
245249

250+
246251
class Traceback(list):
247252
""" Traceback objects encapsulate and offer higher level
248253
access to Traceback entries.
249254
"""
250255
Entry = TracebackEntry
256+
251257
def __init__(self, tb):
252258
""" initialize from given python traceback object. """
253259
if hasattr(tb, 'tb_next'):
@@ -362,7 +368,8 @@ def __init__(self, tup=None, exprinfo=None):
362368
self.traceback = py.code.Traceback(self.tb)
363369

364370
def __repr__(self):
365-
return "<ExceptionInfo %s tblen=%d>" % (self.typename, len(self.traceback))
371+
return "<ExceptionInfo %s tblen=%d>" % (
372+
self.typename, len(self.traceback))
366373

367374
def exconly(self, tryshort=False):
368375
""" return the exception as a string
@@ -391,7 +398,7 @@ def _getreprcrash(self):
391398
return ReprFileLocation(path, lineno+1, exconly)
392399

393400
def getrepr(self, showlocals=False, style="long",
394-
abspath=False, tbfilter=True, funcargs=False):
401+
abspath=False, tbfilter=True, funcargs=False):
395402
""" return str()able representation of this exception info.
396403
showlocals: show locals per traceback entry
397404
style: long|short|no|native traceback style
@@ -401,13 +408,14 @@ def getrepr(self, showlocals=False, style="long",
401408
"""
402409
if style == 'native':
403410
return ReprExceptionInfo(ReprTracebackNative(
404-
py.std.traceback.format_exception(
411+
traceback.format_exception(
405412
self.type,
406413
self.value,
407414
self.traceback[0]._rawentry,
408415
)), self._getreprcrash())
409416

410-
fmt = FormattedExcinfo(showlocals=showlocals, style=style,
417+
fmt = FormattedExcinfo(
418+
showlocals=showlocals, style=style,
411419
abspath=abspath, tbfilter=tbfilter, funcargs=funcargs)
412420
return fmt.repr_excinfo(self)
413421

@@ -428,7 +436,8 @@ class FormattedExcinfo(object):
428436
flow_marker = ">"
429437
fail_marker = "E"
430438

431-
def __init__(self, showlocals=False, style="long", abspath=True, tbfilter=True, funcargs=False):
439+
def __init__(self, showlocals=False, style="long",
440+
abspath=True, tbfilter=True, funcargs=False):
432441
self.showlocals = showlocals
433442
self.style = style
434443
self.tbfilter = tbfilter
@@ -521,7 +530,7 @@ def repr_locals(self, locals):
521530
#else:
522531
# self._line("%-10s =\\" % (name,))
523532
# # XXX
524-
# py.std.pprint.pprint(value, stream=self.excinfowriter)
533+
# pprint.pprint(value, stream=self.excinfowriter)
525534
return ReprLocals(lines)
526535

527536
def repr_traceback_entry(self, entry, excinfo=None):
@@ -779,7 +788,7 @@ def getrawcode(obj, trycall=True):
779788
obj = getattr(obj, 'f_code', obj)
780789
obj = getattr(obj, '__code__', obj)
781790
if trycall and not hasattr(obj, 'co_firstlineno'):
782-
if hasattr(obj, '__call__') and not py.std.inspect.isclass(obj):
791+
if hasattr(obj, '__call__') and not isclass(obj):
783792
x = getrawcode(obj.__call__, trycall=False)
784793
if hasattr(x, 'co_firstlineno'):
785794
return x

py/_code/source.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,8 @@ def compile(self, filename=None, mode='exec',
193193
if flag & _AST_FLAG:
194194
return co
195195
lines = [(x + "\n") for x in self.lines]
196-
py.std.linecache.cache[filename] = (1, None, lines, filename)
196+
import linecache
197+
linecache.cache[filename] = (1, None, lines, filename)
197198
return co
198199

199200
#
@@ -224,8 +225,8 @@ def getfslineno(obj):
224225
code = py.code.Code(obj)
225226
except TypeError:
226227
try:
227-
fn = (py.std.inspect.getsourcefile(obj) or
228-
py.std.inspect.getfile(obj))
228+
fn = (inspect.getsourcefile(obj) or
229+
inspect.getfile(obj))
229230
except TypeError:
230231
return "", -1
231232

@@ -248,7 +249,7 @@ def getfslineno(obj):
248249

249250
def findsource(obj):
250251
try:
251-
sourcelines, lineno = py.std.inspect.findsource(obj)
252+
sourcelines, lineno = inspect.findsource(obj)
252253
except py.builtin._sysex:
253254
raise
254255
except:

py/_io/terminalwriter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def __init__(self, file=None, stringio=False, encoding=None):
129129
if stringio:
130130
self.stringio = file = py.io.TextIO()
131131
else:
132-
file = py.std.sys.stdout
132+
from sys import stdout as file
133133
elif py.builtin.callable(file) and not (
134134
hasattr(file, "write") and hasattr(file, "flush")):
135135
file = WriteFile(file, encoding=encoding)

py/_log/log.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@
1414
debug=py.log.STDOUT,
1515
command=None)
1616
"""
17-
import py, sys
17+
import py
18+
import sys
19+
import syslog
20+
1821

1922
class Message(object):
2023
def __init__(self, keywords, args):
@@ -70,6 +73,7 @@ def __init__(self):
7073

7174
def getstate(self):
7275
return self.keywords2consumer.copy()
76+
7377
def setstate(self, state):
7478
self.keywords2consumer.clear()
7579
self.keywords2consumer.update(state)
@@ -104,29 +108,35 @@ def setconsumer(self, keywords, consumer):
104108
consumer = File(consumer)
105109
self.keywords2consumer[keywords] = consumer
106110

111+
107112
def default_consumer(msg):
108113
""" the default consumer, prints the message to stdout (using 'print') """
109114
sys.stderr.write(str(msg)+"\n")
110115

111116
default_keywordmapper = KeywordMapper()
112117

118+
113119
def setconsumer(keywords, consumer):
114120
default_keywordmapper.setconsumer(keywords, consumer)
115121

122+
116123
def setstate(state):
117124
default_keywordmapper.setstate(state)
125+
126+
118127
def getstate():
119128
return default_keywordmapper.getstate()
120129

121130
#
122131
# Consumers
123132
#
124133

134+
125135
class File(object):
126136
""" log consumer wrapping a file(-like) object """
127137
def __init__(self, f):
128138
assert hasattr(f, 'write')
129-
#assert isinstance(f, file) or not hasattr(f, 'open')
139+
# assert isinstance(f, file) or not hasattr(f, 'open')
130140
self._file = f
131141

132142
def __call__(self, msg):
@@ -135,6 +145,7 @@ def __call__(self, msg):
135145
if hasattr(self._file, 'flush'):
136146
self._file.flush()
137147

148+
138149
class Path(object):
139150
""" log consumer that opens and writes to a Path """
140151
def __init__(self, filename, append=False,
@@ -158,29 +169,32 @@ def __call__(self, msg):
158169
if not self._buffering:
159170
self._file.flush()
160171

172+
161173
def STDOUT(msg):
162174
""" consumer that writes to sys.stdout """
163175
sys.stdout.write(str(msg)+"\n")
164176

177+
165178
def STDERR(msg):
166179
""" consumer that writes to sys.stderr """
167180
sys.stderr.write(str(msg)+"\n")
168181

182+
169183
class Syslog:
170184
""" consumer that writes to the syslog daemon """
171185

172-
def __init__(self, priority = None):
186+
def __init__(self, priority=None):
173187
if priority is None:
174188
priority = self.LOG_INFO
175189
self.priority = priority
176190

177191
def __call__(self, msg):
178192
""" write a message to the log """
179-
py.std.syslog.syslog(self.priority, str(msg))
193+
syslog.syslog(self.priority, str(msg))
180194

181195
for _prio in "EMERG ALERT CRIT ERR WARNING NOTICE INFO DEBUG".split():
182196
_prio = "LOG_" + _prio
183197
try:
184-
setattr(Syslog, _prio, getattr(py.std.syslog, _prio))
198+
setattr(Syslog, _prio, getattr(syslog, _prio))
185199
except AttributeError:
186200
pass

py/_log/warning.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,11 @@ def _apiwarn(startversion, msg, stacklevel=2, function=None):
3232
msg = "%s (since version %s)" %(msg, startversion)
3333
warn(msg, stacklevel=stacklevel+1, function=function)
3434

35+
3536
def warn(msg, stacklevel=1, function=None):
3637
if function is not None:
37-
filename = py.std.inspect.getfile(function)
38+
import inspect
39+
filename = inspect.getfile(function)
3840
lineno = py.code.getrawcode(function).co_firstlineno
3941
else:
4042
try:
@@ -67,10 +69,11 @@ def warn(msg, stacklevel=1, function=None):
6769
filename = module
6870
path = py.path.local(filename)
6971
warning = DeprecationWarning(msg, path, lineno)
70-
py.std.warnings.warn_explicit(warning, category=Warning,
72+
import warnings
73+
warnings.warn_explicit(warning, category=Warning,
7174
filename=str(warning.path),
7275
lineno=warning.lineno,
73-
registry=py.std.warnings.__dict__.setdefault(
76+
registry=warnings.__dict__.setdefault(
7477
"__warningsregistry__", {})
7578
)
7679

py/_path/common.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,14 +189,16 @@ def load(self):
189189
""" (deprecated) return object unpickled from self.read() """
190190
f = self.open('rb')
191191
try:
192-
return py.error.checked_call(py.std.pickle.load, f)
192+
import pickle
193+
return py.error.checked_call(pickle.load, f)
193194
finally:
194195
f.close()
195196

196197
def move(self, target):
197198
""" move this path to target. """
198199
if target.relto(self):
199-
raise py.error.EINVAL(target,
200+
raise py.error.EINVAL(
201+
target,
200202
"cannot move path into a subdirectory of itself")
201203
try:
202204
self.rename(target)
@@ -226,7 +228,7 @@ def check(self, **kw):
226228
path.check(file=1, link=1) # a link pointing to a file
227229
"""
228230
if not kw:
229-
kw = {'exists' : 1}
231+
kw = {'exists': 1}
230232
return self.Checkers(self)._evaluate(kw)
231233

232234
def fnmatch(self, pattern):

0 commit comments

Comments
 (0)