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
8895a32b
Commit
8895a32b
authored
Feb 03, 2009
by
Raymond Hettinger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Validate that __length_hint__ returns a usable result.
parent
10c295dc
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
1 deletion
+11
-1
Lib/test/test_iterlen.py
Lib/test/test_iterlen.py
+10
-0
Objects/abstract.c
Objects/abstract.c
+1
-1
No files found.
Lib/test/test_iterlen.py
View file @
8895a32b
...
@@ -208,6 +208,11 @@ class BadLengthHint(object):
...
@@ -208,6 +208,11 @@ class BadLengthHint(object):
def
__length_hint__
(
self
):
def
__length_hint__
(
self
):
raise
RuntimeError
(
'hello'
)
raise
RuntimeError
(
'hello'
)
class
NoneLengthHint
(
object
):
def
__iter__
(
self
):
return
iter
(
range
(
10
))
def
__length_hint__
(
self
):
return
None
class
TestLengthHintExceptions
(
unittest
.
TestCase
):
class
TestLengthHintExceptions
(
unittest
.
TestCase
):
def
test_issue1242657
(
self
):
def
test_issue1242657
(
self
):
...
@@ -219,6 +224,11 @@ class TestLengthHintExceptions(unittest.TestCase):
...
@@ -219,6 +224,11 @@ class TestLengthHintExceptions(unittest.TestCase):
self
.
assertRaises
(
RuntimeError
,
b
.
extend
,
BadLen
())
self
.
assertRaises
(
RuntimeError
,
b
.
extend
,
BadLen
())
self
.
assertRaises
(
RuntimeError
,
b
.
extend
,
BadLengthHint
())
self
.
assertRaises
(
RuntimeError
,
b
.
extend
,
BadLengthHint
())
def
test_invalid_hint
(
self
):
# Make sure an invalid result doesn't muck-up the works
self
.
assertEqual
(
list
(
NoneLengthHint
()),
list
(
range
(
10
)))
def
test_main
():
def
test_main
():
unittests
=
[
unittests
=
[
TestRepeat
,
TestRepeat
,
...
...
Objects/abstract.c
View file @
8895a32b
...
@@ -105,7 +105,7 @@ _PyObject_LengthHint(PyObject *o, Py_ssize_t defaultvalue)
...
@@ -105,7 +105,7 @@ _PyObject_LengthHint(PyObject *o, Py_ssize_t defaultvalue)
PyErr_Clear
();
PyErr_Clear
();
return
defaultvalue
;
return
defaultvalue
;
}
}
rv
=
PyLong_
AsSsize_t
(
ro
)
;
rv
=
PyLong_
Check
(
ro
)
?
PyLong_AsSsize_t
(
ro
)
:
defaultvalue
;
Py_DECREF
(
ro
);
Py_DECREF
(
ro
);
return
rv
;
return
rv
;
}
}
...
...
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