Skip to content

Commit 15e4367

Browse files
committed
Grab the signature of redis.Redis at module import time
The change of use inspect.signature in jamesls#314 broke code that mocks redis.Redis, because the signature is no longer for the correct function.
1 parent ccd62a9 commit 15e4367

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

fakeredis/_server.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@
8686

8787
FLAG_NO_SCRIPT = 's' # Command not allowed in scripts
8888

89+
# This needs to be grabbed early to avoid breaking tests that mock redis.Redis.
90+
_ORIG_SIG = inspect.signature(redis.Redis)
91+
8992

9093
class SimpleString:
9194
def __init__(self, value):
@@ -2744,8 +2747,7 @@ class FakeRedisMixin:
27442747
def __init__(self, *args, server=None, connected=True, **kwargs):
27452748
# Interpret the positional and keyword arguments according to the
27462749
# version of redis in use.
2747-
sig = inspect.signature(redis.Redis)
2748-
bound = sig.bind(*args, **kwargs)
2750+
bound = _ORIG_SIG.bind(*args, **kwargs)
27492751
bound.apply_defaults()
27502752
if not bound.arguments['connection_pool']:
27512753
charset = bound.arguments['charset']

0 commit comments

Comments
 (0)