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
f847f1fb
Commit
f847f1fb
authored
Jun 24, 2015
by
Yury Selivanov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #24400, #24325: More tests for types._GeneratorWrapper
Also, make 'wrapped' and 'isgen' private.
parent
00e33723
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
13 deletions
+31
-13
Lib/test/test_types.py
Lib/test/test_types.py
+20
-2
Lib/types.py
Lib/types.py
+11
-11
No files found.
Lib/test/test_types.py
View file @
f847f1fb
...
...
@@ -1316,6 +1316,11 @@ class CoroutineTests(unittest.TestCase):
wrapper
.
send
(
1
)
gen
.
send
.
assert_called_once_with
(
1
)
gen
.
reset_mock
()
next
(
wrapper
)
gen
.
__next__
.
assert_called_once_with
()
gen
.
reset_mock
()
wrapper
.
throw
(
1
,
2
,
3
)
gen
.
throw
.
assert_called_once_with
(
1
,
2
,
3
)
...
...
@@ -1412,8 +1417,10 @@ class CoroutineTests(unittest.TestCase):
self
.
fail
(
'StopIteration was expected'
)
def
test_gen
(
self
):
def
gen
():
yield
gen
=
gen
()
def
gen_func
():
yield
1
return
(
yield
2
)
gen
=
gen_func
()
@
types
.
coroutine
def
foo
():
return
gen
wrapper
=
foo
()
...
...
@@ -1426,6 +1433,17 @@ class CoroutineTests(unittest.TestCase):
getattr
(
gen
,
name
))
self
.
assertIs
(
foo
().
cr_code
,
gen
.
gi_code
)
self
.
assertEqual
(
next
(
wrapper
),
1
)
self
.
assertEqual
(
wrapper
.
send
(
None
),
2
)
with
self
.
assertRaisesRegex
(
StopIteration
,
'spam'
):
wrapper
.
send
(
'spam'
)
gen
=
gen_func
()
wrapper
=
foo
()
wrapper
.
send
(
None
)
with
self
.
assertRaisesRegex
(
Exception
,
'ham'
):
wrapper
.
throw
(
Exception
,
Exception
(
'ham'
))
def
test_genfunc
(
self
):
def
gen
():
yield
self
.
assertIs
(
types
.
coroutine
(
gen
),
gen
)
...
...
Lib/types.py
View file @
f847f1fb
...
...
@@ -169,33 +169,33 @@ import collections.abc as _collections_abc
class
_GeneratorWrapper
:
# TODO: Implement this in C.
def
__init__
(
self
,
gen
):
self
.
__wrapped
__
=
gen
self
.
__isgen
__
=
gen
.
__class__
is
GeneratorType
self
.
__wrapped
=
gen
self
.
__isgen
=
gen
.
__class__
is
GeneratorType
self
.
__name__
=
getattr
(
gen
,
'__name__'
,
None
)
self
.
__qualname__
=
getattr
(
gen
,
'__qualname__'
,
None
)
def
send
(
self
,
val
):
return
self
.
__wrapped
__
.
send
(
val
)
return
self
.
__wrapped
.
send
(
val
)
def
throw
(
self
,
tp
,
*
rest
):
return
self
.
__wrapped
__
.
throw
(
tp
,
*
rest
)
return
self
.
__wrapped
.
throw
(
tp
,
*
rest
)
def
close
(
self
):
return
self
.
__wrapped
__
.
close
()
return
self
.
__wrapped
.
close
()
@
property
def
gi_code
(
self
):
return
self
.
__wrapped
__
.
gi_code
return
self
.
__wrapped
.
gi_code
@
property
def
gi_frame
(
self
):
return
self
.
__wrapped
__
.
gi_frame
return
self
.
__wrapped
.
gi_frame
@
property
def
gi_running
(
self
):
return
self
.
__wrapped
__
.
gi_running
return
self
.
__wrapped
.
gi_running
cr_code
=
gi_code
cr_frame
=
gi_frame
cr_running
=
gi_running
def
__next__
(
self
):
return
next
(
self
.
__wrapped
__
)
return
next
(
self
.
__wrapped
)
def
__iter__
(
self
):
if
self
.
__isgen
__
:
return
self
.
__wrapped
__
if
self
.
__isgen
:
return
self
.
__wrapped
return
self
__await__
=
__iter__
...
...
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