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
4d58897f
Commit
4d58897f
authored
Aug 12, 2014
by
Raymond Hettinger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue 22184: Early detection and reporting of missing lru_cache parameters
parent
4d83192e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
0 deletions
+16
-0
Lib/functools.py
Lib/functools.py
+6
-0
Lib/test/test_functools.py
Lib/test/test_functools.py
+7
-0
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Lib/functools.py
View file @
4d58897f
...
@@ -392,6 +392,12 @@ def lru_cache(maxsize=128, typed=False):
...
@@ -392,6 +392,12 @@ def lru_cache(maxsize=128, typed=False):
# The internals of the lru_cache are encapsulated for thread safety and
# The internals of the lru_cache are encapsulated for thread safety and
# to allow the implementation to change (including a possible C version).
# to allow the implementation to change (including a possible C version).
# Early detection of an erroneous call to @lru_cache without any arguments
# resulting in the inner function being passed to maxsize instead of an
# integer or None.
if
maxsize
is
not
None
and
not
isinstance
(
maxsize
,
int
):
raise
TypeError
(
'Expected maxsize to be an integer or None'
)
# Constants shared by all lru cache instances:
# Constants shared by all lru cache instances:
sentinel
=
object
()
# unique object used to signal cache misses
sentinel
=
object
()
# unique object used to signal cache misses
make_key
=
_make_key
# build a key from the function arguments
make_key
=
_make_key
# build a key from the function arguments
...
...
Lib/test/test_functools.py
View file @
4d58897f
...
@@ -1070,6 +1070,13 @@ class TestLRU(unittest.TestCase):
...
@@ -1070,6 +1070,13 @@ class TestLRU(unittest.TestCase):
self
.
assertEqual
(
test_func
(
DoubleEq
(
2
)),
# Trigger a re-entrant __eq__ call
self
.
assertEqual
(
test_func
(
DoubleEq
(
2
)),
# Trigger a re-entrant __eq__ call
DoubleEq
(
2
))
# Verify the correct return value
DoubleEq
(
2
))
# Verify the correct return value
def
test_early_detection_of_bad_call
(
self
):
# Issue #22184
with
self
.
assertRaises
(
TypeError
):
@
functools
.
lru_cache
def
f
():
pass
class
TestSingleDispatch
(
unittest
.
TestCase
):
class
TestSingleDispatch
(
unittest
.
TestCase
):
def
test_simple_overloads
(
self
):
def
test_simple_overloads
(
self
):
...
...
Misc/NEWS
View file @
4d58897f
...
@@ -30,6 +30,9 @@ Library
...
@@ -30,6 +30,9 @@ Library
- Issue #21448: Changed FeedParser feed() to avoid O(N**2) behavior when
- Issue #21448: Changed FeedParser feed() to avoid O(N**2) behavior when
parsing long line. Original patch by Raymond Hettinger.
parsing long line. Original patch by Raymond Hettinger.
- Issue #22184: The functools LRU Cache decorator factory now gives an earlier
and clearer error message when the user forgets the required parameters.
- Issue #17923: glob() patterns ending with a slash no longer match non-dirs on
- Issue #17923: glob() patterns ending with a slash no longer match non-dirs on
AIX. Based on patch by Delhallt.
AIX. Based on patch by Delhallt.
...
...
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