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
cc0def18
Commit
cc0def18
authored
Aug 13, 2004
by
Raymond Hettinger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Convert weak iterators to generator form.
parent
bf9ac4bd
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
51 deletions
+23
-51
Lib/weakref.py
Lib/weakref.py
+23
-51
No files found.
Lib/weakref.py
View file @
cc0def18
...
...
@@ -277,54 +277,26 @@ class WeakKeyDictionary(UserDict.UserDict):
self
.
update
(
kwargs
)
class
BaseIter
:
def
__iter__
(
self
):
return
self
class
WeakKeyedKeyIterator
(
BaseIter
):
def
__init__
(
self
,
weakdict
):
self
.
_next
=
weakdict
.
data
.
iterkeys
().
next
def
next
(
self
):
while
1
:
wr
=
self
.
_next
()
obj
=
wr
()
if
obj
is
not
None
:
return
obj
class
WeakKeyedItemIterator
(
BaseIter
):
def
__init__
(
self
,
weakdict
):
self
.
_next
=
weakdict
.
data
.
iteritems
().
next
def
next
(
self
):
while
1
:
wr
,
value
=
self
.
_next
()
key
=
wr
()
if
key
is
not
None
:
return
key
,
value
class
WeakValuedValueIterator
(
BaseIter
):
def
__init__
(
self
,
weakdict
):
self
.
_next
=
weakdict
.
data
.
itervalues
().
next
def
next
(
self
):
while
1
:
wr
=
self
.
_next
()
obj
=
wr
()
if
obj
is
not
None
:
return
obj
class
WeakValuedItemIterator
(
BaseIter
):
def
__init__
(
self
,
weakdict
):
self
.
_next
=
weakdict
.
data
.
itervalues
().
next
def
next
(
self
):
while
1
:
wr
=
self
.
_next
()
value
=
wr
()
if
value
is
not
None
:
return
wr
.
key
,
value
def
WeakKeyedKeyIterator
(
weakdict
):
for
wr
in
weakdict
.
data
.
iterkeys
():
obj
=
wr
()
if
obj
is
not
None
:
yield
obj
def
WeakKeyedItemIterator
(
weakdict
):
for
wr
,
value
in
weakdict
.
data
.
iteritems
():
key
=
wr
()
if
key
is
not
None
:
yield
key
,
value
def
WeakValuedValueIterator
(
weakdict
):
for
wr
in
weakdict
.
data
.
itervalues
():
obj
=
wr
()
if
obj
is
not
None
:
yield
obj
def
WeakValuedItemIterator
(
weakdict
):
for
wr
in
weakdict
.
data
.
itervalues
():
value
=
wr
()
if
value
is
not
None
:
yield
wr
.
key
,
value
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