Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
7131f844
Commit
7131f844
authored
Feb 09, 2007
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix a bunch of doctests with the -d option of refactor.py.
We still have 27 failing tests (down from 39).
parent
4502c804
Changes
24
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
24 changed files
with
217 additions
and
217 deletions
+217
-217
Lib/Cookie.py
Lib/Cookie.py
+5
-5
Lib/ctypes/test/test_objects.py
Lib/ctypes/test/test_objects.py
+3
-3
Lib/decimal.py
Lib/decimal.py
+24
-24
Lib/difflib.py
Lib/difflib.py
+8
-8
Lib/distutils/versionpredicate.py
Lib/distutils/versionpredicate.py
+1
-1
Lib/doctest.py
Lib/doctest.py
+7
-7
Lib/nntplib.py
Lib/nntplib.py
+1
-1
Lib/smtplib.py
Lib/smtplib.py
+1
-1
Lib/telnetlib.py
Lib/telnetlib.py
+1
-1
Lib/test/doctest_aliases.py
Lib/test/doctest_aliases.py
+1
-1
Lib/test/sample_doctest.py
Lib/test/sample_doctest.py
+3
-3
Lib/test/test_code.py
Lib/test/test_code.py
+3
-3
Lib/test/test_deque.py
Lib/test/test_deque.py
+4
-4
Lib/test/test_descrtut.py
Lib/test/test_descrtut.py
+31
-31
Lib/test/test_doctest.py
Lib/test/test_doctest.py
+43
-43
Lib/test/test_doctest2.py
Lib/test/test_doctest2.py
+13
-13
Lib/test/test_generators.py
Lib/test/test_generators.py
+39
-39
Lib/test/test_genexps.py
Lib/test/test_genexps.py
+3
-3
Lib/test/test_itertools.py
Lib/test/test_itertools.py
+10
-10
Lib/test/test_syntax.py
Lib/test/test_syntax.py
+4
-4
Lib/test/test_urllib2.py
Lib/test/test_urllib2.py
+1
-1
Lib/test/test_weakref.py
Lib/test/test_weakref.py
+4
-4
Lib/test/test_xml_etree.py
Lib/test/test_xml_etree.py
+5
-5
Lib/test/test_xml_etree_c.py
Lib/test/test_xml_etree_c.py
+2
-2
No files found.
Lib/Cookie.py
View file @
7131f844
...
...
@@ -80,9 +80,9 @@ attributes by using the .output() function
>>> C = Cookie.SmartCookie()
>>> C["rocky"] = "road"
>>> C["rocky"]["path"] = "/cookie"
>>> print(
C.output(header="Cookie:"
))
>>> print(
(C.output(header="Cookie:")
))
Cookie: rocky=road; Path=/cookie
>>> print(
C.output(attrs=[], header="Cookie:"
))
>>> print(
(C.output(attrs=[], header="Cookie:")
))
Cookie: rocky=road
The load() method of a Cookie extracts cookies from a string. In a
...
...
@@ -100,7 +100,7 @@ such trickeries do not confuse it.
>>> C = Cookie.SmartCookie()
>>> C.load('keebler="E=everybody; L=\\"Loves\\"; fudge=\\012;";')
>>> print(
C
)
>>> print(
(C)
)
Set-Cookie: keebler="E=everybody; L=\"Loves\"; fudge=\012;"
Each element of the Cookie also supports all of the RFC 2109
...
...
@@ -110,7 +110,7 @@ attribute.
>>> C = Cookie.SmartCookie()
>>> C["oreo"] = "doublestuff"
>>> C["oreo"]["path"] = "/"
>>> print(
C
)
>>> print(
(C)
)
Set-Cookie: oreo=doublestuff; Path=/
Each dictionary element has a 'value' attribute, which gives you
...
...
@@ -198,7 +198,7 @@ it is still possible to use Cookie.Cookie() to create a Cookie. In
fact, this simply returns a SmartCookie.
>>> C = Cookie.Cookie()
>>> print(
C.__class__.__name__
)
>>> print(
(C.__class__.__name__)
)
SmartCookie
...
...
Lib/ctypes/test/test_objects.py
View file @
7131f844
...
...
@@ -13,7 +13,7 @@ Here is an array of string pointers:
>>> from ctypes import *
>>> array = (c_char_p * 5)()
>>> print
array._objects
>>> print
(array._objects)
None
>>>
...
...
@@ -34,14 +34,14 @@ in a 'base' object.
... _fields_ = [("x", c_int), ("y", c_int), ("array", c_char_p * 5)]
...
>>> x = X()
>>> print
x._objects
>>> print
(x._objects)
None
>>>
The'array' attribute of the 'x' object shares part of the memory buffer
of 'x' ('_b_base_' is either None, or the root object owning the memory block):
>>> print
x.array._b_base_
# doctest: +ELLIPSIS
>>> print
(x.array._b_base_)
# doctest: +ELLIPSIS
<ctypes.test.test_objects.X object at 0x...>
>>>
...
...
Lib/decimal.py
View file @
7131f844
...
...
@@ -56,31 +56,31 @@ Decimal("2.60")
>>> Decimal("12.34") + Decimal("3.87") - Decimal("18.41")
Decimal("-2.20")
>>> dig = Decimal(1)
>>> print
dig / Decimal(3
)
>>> print
(dig / Decimal(3)
)
0.333333333
>>> getcontext().prec = 18
>>> print
dig / Decimal(3
)
>>> print
(dig / Decimal(3)
)
0.333333333333333333
>>> print
dig.sqrt(
)
>>> print
(dig.sqrt()
)
1
>>> print
Decimal(3).sqrt(
)
>>> print
(Decimal(3).sqrt()
)
1.73205080756887729
>>> print
Decimal(3) ** 123
>>> print
(Decimal(3) ** 123)
4.85192780976896427E+58
>>> inf = Decimal(1) / Decimal(0)
>>> print
inf
>>> print
(inf)
Infinity
>>> neginf = Decimal(-1) / Decimal(0)
>>> print
neginf
>>> print
(neginf)
-Infinity
>>> print
neginf + inf
>>> print
(neginf + inf)
NaN
>>> print
neginf * inf
>>> print
(neginf * inf)
-Infinity
>>> print
dig / 0
>>> print
(dig / 0)
Infinity
>>> getcontext().traps[DivisionByZero] = 1
>>> print
dig / 0
>>> print
(dig / 0)
Traceback (most recent call last):
...
...
...
...
@@ -88,29 +88,29 @@ Traceback (most recent call last):
decimal.DivisionByZero: x / 0
>>> c = Context()
>>> c.traps[InvalidOperation] = 0
>>> print
c.flags[InvalidOperation]
>>> print
(c.flags[InvalidOperation])
0
>>> c.divide(Decimal(0), Decimal(0))
Decimal("NaN")
>>> c.traps[InvalidOperation] = 1
>>> print
c.flags[InvalidOperation]
>>> print
(c.flags[InvalidOperation])
1
>>> c.flags[InvalidOperation] = 0
>>> print
c.flags[InvalidOperation]
>>> print
(c.flags[InvalidOperation])
0
>>> print
c.divide(Decimal(0), Decimal(0
))
>>> print
(c.divide(Decimal(0), Decimal(0)
))
Traceback (most recent call last):
...
...
...
decimal.InvalidOperation: 0 / 0
>>> print
c.flags[InvalidOperation]
>>> print
(c.flags[InvalidOperation])
1
>>> c.flags[InvalidOperation] = 0
>>> c.traps[InvalidOperation] = 0
>>> print
c.divide(Decimal(0), Decimal(0
))
>>> print
(c.divide(Decimal(0), Decimal(0)
))
NaN
>>> print
c.flags[InvalidOperation]
>>> print
(c.flags[InvalidOperation])
1
>>>
"""
...
...
@@ -483,19 +483,19 @@ def localcontext(ctx=None):
# as the doctest module doesn't understand __future__ statements
"""
>>> from __future__ import with_statement
>>> print
getcontext().prec
>>> print
(getcontext().prec)
28
>>> with localcontext():
... ctx = getcontext()
... ctx.prec() += 2
... print
ctx.prec
...
... print
(ctx.prec)
...
30
>>> with localcontext(ExtendedContext):
... print
getcontext().prec
...
... print
(getcontext().prec)
...
9
>>> print
getcontext().prec
>>> print
(getcontext().prec)
28
"""
if
ctx
is
None
:
ctx
=
getcontext
()
...
...
Lib/difflib.py
View file @
7131f844
...
...
@@ -76,7 +76,7 @@ class SequenceMatcher:
sequences. As a rule of thumb, a .ratio() value over 0.6 means the
sequences are close matches:
>>> print(
round(s.ratio(), 3
))
>>> print(
(round(s.ratio(), 3)
))
0.866
>>>
...
...
@@ -84,7 +84,7 @@ class SequenceMatcher:
.get_matching_blocks() is handy:
>>> for block in s.get_matching_blocks():
... print(
"a[%d] and b[%d] match for %d elements" % block
)
... print(
("a[%d] and b[%d] match for %d elements" % block)
)
a[0] and b[0] match for 8 elements
a[8] and b[17] match for 21 elements
a[29] and b[38] match for 0 elements
...
...
@@ -97,7 +97,7 @@ class SequenceMatcher:
use .get_opcodes():
>>> for opcode in s.get_opcodes():
... print(
"%6s a[%d:%d] b[%d:%d]" % opcode
)
... print(
("%6s a[%d:%d] b[%d:%d]" % opcode)
)
equal a[0:8] b[0:8]
insert a[8:8] b[8:17]
equal a[8:29] b[17:38]
...
...
@@ -545,8 +545,8 @@ class SequenceMatcher:
>>> b = "abycdf"
>>> s = SequenceMatcher(None, a, b)
>>> for tag, i1, i2, j1, j2 in s.get_opcodes():
... print(("%7s a[%d:%d] (%s) b[%d:%d] (%s)" %
... (tag, i1, i2, a[i1:i2], j1, j2, b[j1:j2])))
... print((
(
"%7s a[%d:%d] (%s) b[%d:%d] (%s)" %
... (tag, i1, i2, a[i1:i2], j1, j2, b[j1:j2])))
)
delete a[0:1] (q) b[0:0] ()
equal a[1:3] (ab) b[0:2] (ab)
replace a[3:4] (x) b[2:3] (y)
...
...
@@ -1059,8 +1059,8 @@ class Differ:
>>> d = Differ()
>>> results = d._qformat('\tabcDefghiJkl\n', '\t\tabcdefGhijkl\n',
... ' ^ ^ ^ ', '+ ^ ^ ^ ')
>>> for line in results: print(
repr(line
))
...
>>> for line in results: print(
(repr(line)
))
...
'- \tabcDefghiJkl\n'
'? \t ^ ^ ^\n'
'+ \t\tabcdefGhijkl\n'
...
...
@@ -1165,7 +1165,7 @@ def unified_diff(a, b, fromfile='', tofile='', fromfiledate='',
... 'zero one tree four'.split(), 'Original', 'Current',
... 'Sat Jan 26 23:30:50 1991', 'Fri Jun 06 10:20:52 2003',
... lineterm=''):
... print(
line
)
... print(
(line)
)
--- Original Sat Jan 26 23:30:50 1991
+++ Current Fri Jun 06 10:20:52 2003
@@ -1,4 +1,4 @@
...
...
Lib/distutils/versionpredicate.py
View file @
7131f844
...
...
@@ -40,7 +40,7 @@ class VersionPredicate:
The str() of a `VersionPredicate` provides a normalized
human-readable version of the expression::
>>> print
v
>>> print
(v)
pyepat.abc (> 1.0, < 3333.3a1, != 1555.1b3)
The `satisfied_by()` method can be used to determine with a given
...
...
Lib/doctest.py
View file @
7131f844
...
...
@@ -1012,7 +1012,7 @@ class DocTestRunner:
>>> runner = DocTestRunner(verbose=False)
>>> tests.sort(key = lambda test: test.name)
>>> for test in tests:
... print
test.name, '->', runner.run(test
)
... print
(test.name, '->', runner.run(test)
)
_TestClass -> (0, 2)
_TestClass.__init__ -> (0, 2)
_TestClass.get -> (0, 2)
...
...
@@ -2419,7 +2419,7 @@ def script_from_examples(s):
... Ho hum
... '''
>>> print
script_from_examples(text
)
>>> print
(script_from_examples(text)
)
# Here are examples of simple math.
#
# Python has super accurate integer addition
...
...
@@ -2554,7 +2554,7 @@ class _TestClass:
"""val -> _TestClass object with associated value val.
>>> t = _TestClass(123)
>>> print
t.get(
)
>>> print
(t.get()
)
123
"""
...
...
@@ -2574,7 +2574,7 @@ class _TestClass:
"""get() -> return TestClass's associated value.
>>> x = _TestClass(-42)
>>> print
x.get(
)
>>> print
(x.get()
)
-42
"""
...
...
@@ -2606,7 +2606,7 @@ __test__ = {"_TestClass": _TestClass,
"blank lines"
:
r"""
Blank lines can be marked with <BLANKLINE>:
>>> print
'foo\n\nbar\n'
>>> print
('foo\n\nbar\n')
foo
<BLANKLINE>
bar
...
...
@@ -2616,14 +2616,14 @@ __test__ = {"_TestClass": _TestClass,
"ellipsis"
:
r"""
If the ellipsis flag is used, then '...' can be used to
elide substrings in the desired output:
>>> print
range(1000
) #doctest: +ELLIPSIS
>>> print
(range(1000)
) #doctest: +ELLIPSIS
[0, 1, 2, ..., 999]
"""
,
"whitespace normalization"
:
r"""
If the whitespace normalization flag is used, then
differences in whitespace are ignored.
>>> print
range(30
) #doctest: +NORMALIZE_WHITESPACE
>>> print
(range(30)
) #doctest: +NORMALIZE_WHITESPACE
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
27, 28, 29]
...
...
Lib/nntplib.py
View file @
7131f844
...
...
@@ -5,7 +5,7 @@ Example:
>>> from nntplib import NNTP
>>> s = NNTP('news')
>>> resp, count, first, last, name = s.group('comp.lang.python')
>>> print
'Group', name, 'has', count, 'articles, range', first, 'to', last
>>> print
('Group', name, 'has', count, 'articles, range', first, 'to', last)
Group comp.lang.python has 51 articles, range 5770 to 5821
>>> resp, subs = s.xhdr('subject', first + '-' + last)
>>> resp = s.quit()
...
...
Lib/smtplib.py
View file @
7131f844
...
...
@@ -15,7 +15,7 @@ Example:
>>> import smtplib
>>> s=smtplib.SMTP("localhost")
>>> print
s.help(
)
>>> print
(s.help()
)
This is Sendmail version 8.8.4
Topics:
HELO EHLO MAIL RCPT DATA
...
...
Lib/telnetlib.py
View file @
7131f844
...
...
@@ -8,7 +8,7 @@ Example:
>>> from telnetlib import Telnet
>>> tn = Telnet('www.python.org', 79) # connect to finger port
>>> tn.write('guido\r\n')
>>> print
tn.read_all(
)
>>> print
(tn.read_all()
)
Login Name TTY Idle When Where
guido Guido van Rossum pts/2 <Dec 2 11:10> snag.cnri.reston..
...
...
Lib/test/doctest_aliases.py
View file @
7131f844
...
...
@@ -5,7 +5,7 @@ class TwoNames:
def
f
(
self
):
'''
>>> print
TwoNames().f(
)
>>> print
(TwoNames().f()
)
f
'''
return
'f'
...
...
Lib/test/sample_doctest.py
View file @
7131f844
...
...
@@ -40,9 +40,9 @@ def test_silly_setup():
def
w_blank
():
"""
>>> if 1:
... print
'a'
... print
... print
'b'
... print
('a')
... print
()
... print
('b')
a
<BLANKLINE>
b
...
...
Lib/test/test_code.py
View file @
7131f844
...
...
@@ -50,9 +50,9 @@ flags: 67
consts: ('None',)
>>> def attrs(obj):
... print
obj.attr1
... print
obj.attr2
... print
obj.attr3
... print
(obj.attr1)
... print
(obj.attr2)
... print
(obj.attr3)
>>> dump(attrs.func_code)
name: attrs
...
...
Lib/test/test_deque.py
View file @
7131f844
...
...
@@ -504,7 +504,7 @@ Example from the Library Reference: Doc/lib/libcollections.tex
>>> from collections import deque
>>> d = deque('ghi') # make a new deque with three items
>>> for elem in d: # iterate over the deque's elements
... print
elem.upper(
)
... print
(elem.upper()
)
G
H
I
...
...
@@ -574,8 +574,8 @@ deque(['a', 'b', 'd', 'e', 'f'])
...
>>> for value in roundrobin('abc', 'd', 'efgh'):
... print
value
...
... print
(value)
...
a
d
e
...
...
@@ -593,7 +593,7 @@ h
... d.append(pair)
... return list(d)
...
>>> print
maketree('abcdefgh'
)
>>> print
(maketree('abcdefgh')
)
[[[['a', 'b'], ['c', 'd']], [['e', 'f'], ['g', 'h']]]]
"""
...
...
Lib/test/test_descrtut.py
View file @
7131f844
...
...
@@ -36,28 +36,28 @@ test_1 = """
Here's the new type at work:
>>> print
defaultdict
# show our type
>>> print
(defaultdict)
# show our type
<class 'test.test_descrtut.defaultdict'>
>>> print
type(defaultdict
) # its metatype
>>> print
(type(defaultdict)
) # its metatype
<type 'type'>
>>> a = defaultdict(default=0.0) # create an instance
>>> print
a
# show the instance
>>> print
(a)
# show the instance
{}
>>> print
type(a
) # show its type
>>> print
(type(a)
) # show its type
<class 'test.test_descrtut.defaultdict'>
>>> print
a.__class__
# show its class
>>> print
(a.__class__)
# show its class
<class 'test.test_descrtut.defaultdict'>
>>> print
type(a) is a.__class__
# its type is its class
>>> print
(type(a) is a.__class__)
# its type is its class
True
>>> a[1] = 3.25 # modify the instance
>>> print
a
# show the new value
>>> print
(a)
# show the new value
{1: 3.25}
>>> print
a[1]
# show the new item
>>> print
(a[1])
# show the new item
3.25
>>> print
a[0]
# a non-existant item
>>> print
(a[0])
# a non-existant item
0.0
>>> a.merge({1:100, 2:200}) # use a dict method
>>> print
sortdict(a
) # show the result
>>> print
(sortdict(a)
) # show the result
{1: 3.25, 2: 200}
>>>
...
...
@@ -65,13 +65,13 @@ We can also use the new type in contexts where classic only allows "real"
dictionaries, such as the locals/globals dictionaries for the exec
statement or the built-in function eval():
>>> print
sorted(a.keys(
))
>>> print
(sorted(a.keys()
))
[1, 2]
>>> exec("x = 3; print x", a)
3
>>> print
sorted(a.keys(), key=lambda x: (str(type(x)), x
))
>>> print
(sorted(a.keys(), key=lambda x: (str(type(x)), x)
))
[1, 2, '__builtins__', 'x']
>>> print
a['x']
>>> print
(a['x'])
3
>>>
...
...
@@ -79,21 +79,21 @@ Now I'll show that defaultdict instances have dynamic instance variables,
just like classic classes:
>>> a.default = -1
>>> print
a["noway"]
>>> print
(a["noway"])
-1
>>> a.default = -1000
>>> print
a["noway"]
>>> print
(a["noway"])
-1000
>>> 'default' in dir(a)
True
>>> a.x1 = 100
>>> a.x2 = 200
>>> print
a.x1
>>> print
(a.x1)
100
>>> d = dir(a)
>>> 'default' in d and 'x1' in d and 'x2' in d
True
>>> print
sortdict(a.__dict__
)
>>> print
(sortdict(a.__dict__)
)
{'default': -1000, 'x1': 100, 'x2': 200}
>>>
"""
...
...
@@ -242,10 +242,10 @@ methods. Static methods are easy to describe: they behave pretty much like
static methods in C++ or Java. Here's an example:
>>> class C:
...
...
... @staticmethod
... def foo(x, y):
... print
"staticmethod", x, y
... print
("staticmethod", x, y)
>>> C.foo(1, 2)
staticmethod 1 2
...
...
@@ -259,7 +259,7 @@ implicit first argument that is the *class* for which they are invoked.
>>> class C:
... @classmethod
... def foo(cls, y):
... print
"classmethod", cls, y
... print
("classmethod", cls, y)
>>> C.foo(1)
classmethod <class 'test.test_descrtut.C'> 1
...
...
@@ -285,7 +285,7 @@ But notice this:
>>> class E(C):
... @classmethod
... def foo(cls, y): # override C.foo
... print
"E.foo() called"
... print
("E.foo() called")
... C.foo(y)
>>> E.foo(1)
...
...
@@ -343,10 +343,10 @@ Here's a small demonstration:
>>> a = C()
>>> a.x = 10
>>> print
a.x
>>> print
(a.x)
10
>>> a.x = -10
>>> print
a.x
>>> print
(a.x)
0
>>>
...
...
@@ -369,10 +369,10 @@ Hmm -- property is builtin now, so let's try it that way too.
>>> a = C()
>>> a.x = 10
>>> print
a.x
>>> print
(a.x)
10
>>> a.x = -10
>>> print
a.x
>>> print
(a.x)
0
>>>
"""
...
...
@@ -385,12 +385,12 @@ This example is implicit in the writeup.
>>> class A: # implicit new-style class
... def save(self):
... print
"called A.save()"
... print
("called A.save()")
>>> class B(A):
... pass
>>> class C(A):
... def save(self):
... print
"called C.save()"
... print
("called C.save()")
>>> class D(B, C):
... pass
...
...
@@ -399,12 +399,12 @@ called C.save()
>>> class A(object): # explicit new-style class
... def save(self):
... print
"called A.save()"
... print
("called A.save()")
>>> class B(A):
... pass
>>> class C(A):
... def save(self):
... print
"called C.save()"
... print
("called C.save()")
>>> class D(B, C):
... pass
...
...
@@ -433,7 +433,7 @@ test_7 = """
Cooperative methods and "super"
>>> print
D().m(
) # "DCBA"
>>> print
(D().m()
) # "DCBA"
DCBA
"""
...
...
@@ -443,7 +443,7 @@ Backwards incompatibilities
>>> class A:
... def foo(self):
... print
"called A.foo()"
... print
("called A.foo()")
>>> class B(A):
... pass
...
...
Lib/test/test_doctest.py
View file @
7131f844
This diff is collapsed.
Click to expand it.
Lib/test/test_doctest2.py
View file @
7131f844
...
...
@@ -2,7 +2,7 @@
u"""A module to test whether doctest recognizes some 2.2 features,
like static and class methods.
>>> print
'yup'
# 1
>>> print
('yup')
# 1
yup
We include some (random) encoded (utf-8) text in the text surrounding
...
...
@@ -17,7 +17,7 @@ from test import test_support
class
C
(
object
):
u"""Class C.
>>> print
C(
) # 2
>>> print
(C()
) # 2
42
...
...
@@ -31,13 +31,13 @@ class C(object):
def
__init__
(
self
):
"""C.__init__.
>>> print
C(
) # 3
>>> print
(C()
) # 3
42
"""
def
__str__
(
self
):
"""
>>> print
C(
) # 4
>>> print
(C()
) # 4
42
"""
return
"42"
...
...
@@ -45,13 +45,13 @@ class C(object):
class
D
(
object
):
"""A nested D class.
>>> print
"In D!"
# 5
>>> print
("In D!")
# 5
In D!
"""
def
nested
(
self
):
"""
>>> print
3
# 6
>>> print
(3)
# 6
3
"""
...
...
@@ -59,7 +59,7 @@ class C(object):
"""
>>> c = C() # 7
>>> c.x = 12 # 8
>>> print
c.x
# 9
>>> print
(c.x)
# 9
-12
"""
return
-
self
.
_x
...
...
@@ -68,7 +68,7 @@ class C(object):
"""
>>> c = C() # 10
>>> c.x = 12 # 11
>>> print
c.x
# 12
>>> print
(c.x)
# 12
-12
"""
self
.
_x
=
value
...
...
@@ -76,7 +76,7 @@ class C(object):
x
=
property
(
getx
,
setx
,
doc
=
"""
\
>>> c = C() # 13
>>> c.x = 12 # 14
>>> print
c.x
# 15
>>> print
(c.x)
# 15
-12
"""
)
...
...
@@ -85,9 +85,9 @@ class C(object):
"""
A static method.
>>> print
C.statm(
) # 16
>>> print
(C.statm()
) # 16
666
>>> print
C().statm(
) # 17
>>> print
(C().statm()
) # 17
666
"""
return
666
...
...
@@ -97,9 +97,9 @@ class C(object):
"""
A class method.
>>> print
C.clsm(22
) # 18
>>> print
(C.clsm(22)
) # 18
22
>>> print
C().clsm(23
) # 19
>>> print
(C().clsm(23)
) # 19
23
"""
return
val
...
...
Lib/test/test_generators.py
View file @
7131f844
...
...
@@ -6,7 +6,7 @@ Let's try a simple generator:
... yield 2
>>> for i in f():
... print
i
... print
(i)
1
2
>>> g = f()
...
...
@@ -78,7 +78,7 @@ However, they are not exactly equivalent:
... raise StopIteration
... except:
... yield 42
>>> print
list(g2(
))
>>> print
(list(g2()
))
[42]
This may be surprising at first:
...
...
@@ -105,14 +105,14 @@ Generators always return to the most recent caller:
>>> def creator():
... r = yrange(5)
... print
"creator", r.next(
)
... print
("creator", r.next()
)
... return r
...
...
>>> def caller():
... r = creator()
... for i in r:
... print
"caller", i
...
... print
("caller", i)
...
>>> caller()
creator 0
caller 1
...
...
@@ -161,7 +161,7 @@ Specification: Return
... return
... except:
... yield 1
>>> print
list(f1(
))
>>> print
(list(f1()
))
[]
because, as in any function, return simply exits, but
...
...
@@ -171,7 +171,7 @@ Specification: Return
... raise StopIteration
... except:
... yield 42
>>> print
list(f2(
))
>>> print
(list(f2()
))
[42]
because StopIteration is captured by a bare "except", as is any
...
...
@@ -221,7 +221,7 @@ Specification: Try/Except/Finally
... finally:
... yield 10
... yield 11
>>> print
list(f(
))
>>> print
(list(f()
))
[1, 2, 4, 5, 8, 9, 10, 11]
>>>
...
...
@@ -270,7 +270,7 @@ Guido's binary tree example.
>>> t = tree("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
>>> # Print the nodes of the tree in in-order.
>>> for x in t:
... print
x,
... print
(x, end=' ')
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
>>> # A non-recursive generator.
...
...
@@ -291,7 +291,7 @@ Guido's binary tree example.
>>> # Exercise the non-recursive generator.
>>> for x in t:
... print
x,
... print
(x, end=' ')
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
"""
...
...
@@ -345,9 +345,9 @@ Next one was posted to c.l.py.
>>> seq = range(1, 5)
>>> for k in range(len(seq) + 2):
... print
"%d-combs of %s:" % (k, seq
)
... print
("%d-combs of %s:" % (k, seq)
)
... for c in gcomb(seq, k):
... print
" ", c
... print
(" ", c)
0-combs of [1, 2, 3, 4]:
[]
1-combs of [1, 2, 3, 4]:
...
...
@@ -383,7 +383,7 @@ From the Iterators list, about the types of these things.
<type 'generator'>
>>> [s for s in dir(i) if not s.startswith('_')]
['close', 'gi_frame', 'gi_running', 'next', 'send', 'throw']
>>> print
i.next.__doc__
>>> print
(i.next.__doc__)
x.next() -> the next value, or raise StopIteration
>>> iter(i) is i
True
...
...
@@ -447,14 +447,14 @@ Subject: Re: PEP 255: Simple Generators
>>> gen = random.WichmannHill(42)
>>> while 1:
... for s in sets:
... print
"%s->%s" % (s, s.find()),
... print
... print
("%s->%s" % (s, s.find()), end=' ')
... print
()
... if len(roots) > 1:
... s1 = gen.choice(roots)
... roots.remove(s1)
... s2 = gen.choice(roots)
... s1.union(s2)
... print
"merged", s1, "into", s2
... print
("merged", s1, "into", s2)
... else:
... break
A->A B->B C->C D->D E->E F->F G->G H->H I->I J->J K->K L->L M->M
...
...
@@ -576,7 +576,7 @@ address space, and it *looked* like a very slow leak.
>>> result = m235()
>>> for i in range(3):
... print
firstn(result, 15
)
... print
(firstn(result, 15)
)
[1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, 16, 18, 20, 24]
[25, 27, 30, 32, 36, 40, 45, 48, 50, 54, 60, 64, 72, 75, 80]
[81, 90, 96, 100, 108, 120, 125, 128, 135, 144, 150, 160, 162, 180, 192]
...
...
@@ -613,7 +613,7 @@ efficient.
>>> m235 = LazyList(m235())
>>> for i in range(5):
... print
[m235[j] for j in range(15*i, 15*(i+1))]
... print
([m235[j] for j in range(15*i, 15*(i+1))])
[1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, 16, 18, 20, 24]
[25, 27, 30, 32, 36, 40, 45, 48, 50, 54, 60, 64, 72, 75, 80]
[81, 90, 96, 100, 108, 120, 125, 128, 135, 144, 150, 160, 162, 180, 192]
...
...
@@ -684,7 +684,7 @@ m235 to share a single generator".
>>> it = m235()
>>> for i in range(5):
... print
firstn(it, 15
)
... print
(firstn(it, 15)
)
[1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, 16, 18, 20, 24]
[25, 27, 30, 32, 36, 40, 45, 48, 50, 54, 60, 64, 72, 75, 80]
[81, 90, 96, 100, 108, 120, 125, 128, 135, 144, 150, 160, 162, 180, 192]
...
...
@@ -890,13 +890,13 @@ This one caused a crash (see SF bug 567538):
... yield i
...
>>> g = f()
>>> print
g.next(
)
>>> print
(g.next()
)
0
>>> print
g.next(
)
>>> print
(g.next()
)
1
>>> print
g.next(
)
>>> print
(g.next()
)
2
>>> print
g.next(
)
>>> print
(g.next()
)
Traceback (most recent call last):
StopIteration
"""
...
...
@@ -1291,7 +1291,7 @@ Generate the 3-bit binary numbers in order. This illustrates dumbest-
possible use of conjoin, just to generate the full cross-product.
>>> for c in conjoin([lambda: iter((0, 1))] * 3):
... print
c
... print
(c)
[0, 0, 0]
[0, 0, 1]
[0, 1, 0]
...
...
@@ -1311,7 +1311,7 @@ generated sequence, you need to copy its results.
>>> for n in range(10):
... all = list(gencopy(conjoin([lambda: iter((0, 1))] * n)))
... print
n, len(all), all[0] == [0] * n, all[-1] == [1] * n
... print
(n, len(all), all[0] == [0] * n, all[-1] == [1] * n)
0 1 True True
1 2 True True
2 4 True True
...
...
@@ -1331,7 +1331,7 @@ And run an 8-queens solver.
>>> for row2col in q.solve():
... count += 1
... if count <= LIMIT:
... print
"Solution", count
... print
("Solution", count)
... q.printsolution(row2col)
Solution 1
+-+-+-+-+-+-+-+-+
...
...
@@ -1370,7 +1370,7 @@ Solution 2
| | | | |Q| | | |
+-+-+-+-+-+-+-+-+
>>> print
count, "solutions in all."
>>> print
(count, "solutions in all.")
92 solutions in all.
And run a Knight's Tour on a 10x10 board. Note that there are about
...
...
@@ -1382,7 +1382,7 @@ And run a Knight's Tour on a 10x10 board. Note that there are about
>>> for x in k.solve():
... count += 1
... if count <= LIMIT:
... print
"Solution", count
... print
("Solution", count)
... k.printsolution(x)
... else:
... break
...
...
@@ -1460,7 +1460,7 @@ coroutine_tests = """\
Sending a value into a started generator:
>>> def f():
... print
(yield 1
)
... print
((yield 1)
)
... yield 2
>>> g = f()
>>> g.next()
...
...
@@ -1507,16 +1507,16 @@ A yield expression with augmented assignment.
>>> seq = []
>>> c = coroutine(seq)
>>> c.next()
>>> print
seq
>>> print
(seq)
[]
>>> c.send(10)
>>> print
seq
>>> print
(seq)
[10]
>>> c.send(10)
>>> print
seq
>>> print
(seq)
[10, 20]
>>> c.send(10)
>>> print
seq
>>> print
(seq)
[10, 20, 30]
...
...
@@ -1553,9 +1553,9 @@ Now check some throw() conditions:
>>> def f():
... while True:
... try:
... print
(yield
)
... print
((yield)
)
... except ValueError as v:
... print
"caught ValueError (%s)" % (v),
... print
("caught ValueError (%s)" % (v), end=' ')
>>> import sys
>>> g = f()
>>> g.next()
...
...
@@ -1616,7 +1616,7 @@ Traceback (most recent call last):
...
TypeError
>>> print
g.gi_frame
>>> print
(g.gi_frame)
None
>>> g.send(2)
...
...
@@ -1639,7 +1639,7 @@ Now let's try closing a generator:
>>> def f():
... try: yield
... except GeneratorExit:
... print
"exiting"
... print
("exiting")
>>> g = f()
>>> g.next()
...
...
@@ -1660,7 +1660,7 @@ And finalization:
>>> def f():
... try: yield
... finally:
... print
"exiting"
... print
("exiting")
>>> g = f()
>>> g.next()
...
...
Lib/test/test_genexps.py
View file @
7131f844
...
...
@@ -157,12 +157,12 @@ Generators always return to the most recent caller:
>>> def creator():
... r = yrange(5)
... print
"creator", r.next(
)
... print
("creator", r.next()
)
... return r
>>> def caller():
... r = creator()
... for i in r:
... print
"caller", i
... print
("caller", i)
>>> caller()
creator 0
caller 1
...
...
@@ -221,7 +221,7 @@ Check that generator attributes are present
>>> set(attr for attr in dir(g) if not attr.startswith('__')) >= expected
True
>>> print
g.next.__doc__
>>> print
(g.next.__doc__)
x.next() -> the next value, or raise StopIteration
>>> import types
>>> isinstance(g, types.GeneratorType)
...
...
Lib/test/test_itertools.py
View file @
7131f844
...
...
@@ -764,24 +764,24 @@ libreftest = """ Doctest for examples in the library reference: libitertools.tex
>>> amounts = [120.15, 764.05, 823.14]
>>> for checknum, amount in izip(count(1200), amounts):
... print
'Check %d is for $%.2f' % (checknum, amount
)
...
... print
('Check %d is for $%.2f' % (checknum, amount)
)
...
Check 1200 is for $120.15
Check 1201 is for $764.05
Check 1202 is for $823.14
>>> import operator
>>> for cube in imap(operator.pow, xrange(1,4), repeat(3)):
... print
cube
...
... print
(cube)
...
1
8
27
>>> reportlines = ['EuroPython', 'Roster', '', 'alex', '', 'laura', '', 'martin', '', 'walter', '', 'samuele']
>>> for name in islice(reportlines, 3, None, 2):
... print
name.title(
)
...
... print
(name.title()
)
...
Alex
Laura
Martin
...
...
@@ -792,8 +792,8 @@ Samuele
>>> d = dict(a=1, b=2, c=1, d=2, e=1, f=2, g=3)
>>> di = sorted(sorted(d.iteritems()), key=itemgetter(1))
>>> for k, g in groupby(di, itemgetter(1)):
... print
k, map(itemgetter(0), g
)
...
... print
(k, map(itemgetter(0), g)
)
...
1 ['a', 'c', 'e']
2 ['b', 'd', 'f']
3 ['g']
...
...
@@ -803,8 +803,8 @@ Samuele
# same group.
>>> data = [ 1, 4,5,6, 10, 15,16,17,18, 22, 25,26,27,28]
>>> for k, g in groupby(enumerate(data), lambda (i,x):i-x):
... print
map(operator.itemgetter(1), g
)
...
... print
(map(operator.itemgetter(1), g)
)
...
[1]
[4, 5, 6]
[10]
...
...
Lib/test/test_syntax.py
View file @
7131f844
...
...
@@ -247,7 +247,7 @@ continue in for loop under finally shouuld be ok.
... finally:
... for abc in range(10):
... continue
... print
abc
... print
(abc)
>>> test()
9
...
...
@@ -328,11 +328,11 @@ so we need to be sure that a break is actually inside a loop. If it
isn't, there should be a syntax error.
>>> try:
... print
1
... print
(1)
... break
... print
2
... print
(2)
... finally:
... print
3
... print
(3)
Traceback (most recent call last):
...
SyntaxError: 'break' outside loop (<doctest test.test_syntax[42]>, line 3)
...
...
Lib/test/test_urllib2.py
View file @
7131f844
...
...
@@ -101,7 +101,7 @@ def test_request_headers_methods():
>>> r.has_header("Not-there")
False
>>> print
r.get_header("Not-there"
)
>>> print
(r.get_header("Not-there")
)
None
>>> r.get_header("Not-there", "default")
'default'
...
...
Lib/test/test_weakref.py
View file @
7131f844
...
...
@@ -1072,7 +1072,7 @@ libreftest = """ Doctest for examples in the library reference: libweakref.tex
...
>>> obj = Dict(red=1, green=2, blue=3) # this object is weak referencable
>>> r = weakref.ref(obj)
>>> print
r() is obj
>>> print
(r() is obj)
True
>>> import weakref
...
...
@@ -1085,7 +1085,7 @@ True
>>> o is o2
True
>>> del o, o2
>>> print
r(
)
>>> print
(r()
)
None
>>> import weakref
...
...
@@ -1140,9 +1140,9 @@ True
>>> try:
... id2obj(a_id)
... except KeyError:
... print
'OK'
... print
('OK')
... else:
... print
'WeakValueDictionary error'
... print
('WeakValueDictionary error')
OK
"""
...
...
Lib/test/test_xml_etree.py
View file @
7131f844
...
...
@@ -184,9 +184,9 @@ def parseliteral():
>>> element = ET.fromstring("<html><body>text</body></html>")
>>> ET.ElementTree(element).write(sys.stdout)
<html><body>text</body></html>
>>> print
ET.tostring(element
)
>>> print
(ET.tostring(element)
)
<html><body>text</body></html>
>>> print
ET.tostring(element, "ascii"
)
>>> print
(ET.tostring(element, "ascii")
)
<?xml version='1.0' encoding='ascii'?>
<html><body>text</body></html>
>>> _, ids = ET.XMLID("<html><body>text</body></html>")
...
...
@@ -301,7 +301,7 @@ def xinclude():
>>> document = xinclude_loader("C1.xml")
>>> ElementInclude.include(document, xinclude_loader)
>>> print
serialize(ET, document
) # C1
>>> print
(serialize(ET, document)
) # C1
<document>
<p>120 Mz is adequate for an average home user.</p>
<disclaimer>
...
...
@@ -315,7 +315,7 @@ def xinclude():
>>> document = xinclude_loader("C2.xml")
>>> ElementInclude.include(document, xinclude_loader)
>>> print
serialize(ET, document
) # C2
>>> print
(serialize(ET, document)
) # C2
<document>
<p>This document has been accessed
324387 times.</p>
...
...
@@ -325,7 +325,7 @@ def xinclude():
>>> document = xinclude_loader("C3.xml")
>>> ElementInclude.include(document, xinclude_loader)
>>> print
serialize(ET, document
) # C3
>>> print
(serialize(ET, document)
) # C3
<document>
<p>The following is the source of the "data.xml" resource:</p>
<example><?xml version='1.0'?>
...
...
Lib/test/test_xml_etree_c.py
View file @
7131f844
...
...
@@ -176,9 +176,9 @@ def parseliteral():
>>> element = ET.fromstring("<html><body>text</body></html>")
>>> ET.ElementTree(element).write(sys.stdout)
<html><body>text</body></html>
>>> print
ET.tostring(element
)
>>> print
(ET.tostring(element)
)
<html><body>text</body></html>
>>> print
ET.tostring(element, "ascii"
)
>>> print
(ET.tostring(element, "ascii")
)
<?xml version='1.0' encoding='ascii'?>
<html><body>text</body></html>
>>> _, ids = ET.XMLID("<html><body>text</body></html>")
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment