Skip to content

Commit

Permalink
Fix python3.8 redis4.2+ issue (#6)
Browse files Browse the repository at this point in the history
Add support for redis-py4.3.1.
Remove python3.7.

Fix issues #3, #5
  • Loading branch information
cunla authored May 14, 2022
1 parent 9a8bfaa commit 6e07519
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 56 deletions.
34 changes: 3 additions & 31 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,49 +18,21 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10"]
redis-py: ["4.1.2", "4.2.2"]
python-version: ["3.8", "3.9", "3.10"]
redis-py: ["4.1.2", "4.3.1"]
aioredis: ["2.0.1"]
exclude:
- python-version: "3.7"
redis-py: "4.2.2"
aioredis: "2.0.1"
- python-version: "3.8"
redis-py: "4.2.2"
aioredis: "2.0.1"
include:
- python-version: "3.9"
redis-py: "4.2.*"
aioredis: "1.3.1"
- python-version: "3.10"
redis-py: "2.10.6"
aioredis: "1.3.1"
- python-version: "3.10"
redis-py: "3.0.1"
aioredis: "1.3.1"
- python-version: "3.10"
redis-py: "3.1.0"
aioredis: "1.3.1"
- python-version: "3.10"
redis-py: "3.2.1"
aioredis: "1.3.1"
- python-version: "3.10"
redis-py: "3.3.11"
aioredis: "1.3.1"
- python-version: "3.10"
redis-py: "3.4.1"
aioredis: "1.3.1"
- python-version: "3.10"
redis-py: "3.5.3"
aioredis: "1.3.1"
- python-version: "3.10"
redis-py: "4.0.1"
aioredis: "1.3.1"
- python-version: "3.10"
redis-py: "4.1.*"
aioredis: "2.0.1"
- python-version: "3.10"
redis-py: "4.2.*"
redis-py: "4.2.2"
aioredis: "2.0.1"
coverage: yes
services:
Expand Down
2 changes: 1 addition & 1 deletion fakeredis/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from ._server import FakeServer, FakeRedis, FakeStrictRedis, FakeConnection # noqa: F401


__version__ = '1.7.4'
__version__ = '1.7.5'
29 changes: 16 additions & 13 deletions fakeredis/_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import inspect
import itertools
import logging
import math
import pickle
import queue
import random
Expand All @@ -15,6 +14,7 @@
from collections import defaultdict
from collections.abc import MutableMapping

import math
import redis
import six

Expand Down Expand Up @@ -87,7 +87,7 @@
FLAG_NO_SCRIPT = 's' # Command not allowed in scripts

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


class SimpleString:
Expand Down Expand Up @@ -2799,20 +2799,23 @@ class FakeRedisMixin:
def __init__(self, *args, server=None, connected=True, **kwargs):
# Interpret the positional and keyword arguments according to the
# version of redis in use.
bound = _ORIG_SIG.bind(*args, **kwargs)
bound.apply_defaults()
if not bound.arguments['connection_pool']:
charset = bound.arguments['charset']
errors = bound.arguments['errors']
default_args = inspect.signature(redis.Redis.__init__).parameters.values()
kwds = {p.name: p.default for p in default_args if p.default != inspect._empty}
kwds.update(kwargs)
# bound = _ORIG_SIG.bind(*args, **params)
# kwds = bound.arguments['kwds']
if not kwds['connection_pool']:
charset = kwds['charset']
errors = kwds['errors']
# Adapted from redis-py
if charset is not None:
warnings.warn(DeprecationWarning(
'"charset" is deprecated. Use "encoding" instead'))
bound.arguments['encoding'] = charset
kwds['encoding'] = charset
if errors is not None:
warnings.warn(DeprecationWarning(
'"errors" is deprecated. Use "encoding_errors" instead'))
bound.arguments['encoding_errors'] = errors
kwds['encoding_errors'] = errors

if server is None:
server = FakeServer()
Expand All @@ -2835,10 +2838,10 @@ def __init__(self, *args, server=None, connected=True, **kwargs):
'client_name'
]
for arg in conn_pool_args:
if arg in bound.arguments:
kwargs[arg] = bound.arguments[arg]
bound.arguments['connection_pool'] = redis.connection.ConnectionPool(**kwargs)
super().__init__(*bound.args, **bound.kwargs)
if arg in kwds:
kwargs[arg] = kwds[arg]
kwds['connection_pool'] = redis.connection.ConnectionPool(**kwargs)
super().__init__(*args, **kwds)

@classmethod
def from_url(cls, *args, **kwargs):
Expand Down
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
invoke==1.7.0
invoke==1.7.1
wheel==0.37.1
tox==3.25.0
twine==4.0.0
Expand Down
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ aioredis==2.0.1
async-timeout==4.0.2
attrs==21.4.0
deprecated==1.2.13
hypothesis==6.45.0
hypothesis==6.46.3
lupa==1.13
packaging==21.3
redis==4.2.2
redis==4.3.1
six==1.16.0
typing-extensions==4.2.0
wrapt==1.14.0
wrapt==1.14.1
zipp==3.8.0
9 changes: 2 additions & 7 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ classifiers =
Development Status :: 5 - Production/Stable
License :: OSI Approved :: BSD License
Programming Language :: Python :: 3
Programming Language :: Python :: 3.6
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Expand All @@ -24,21 +23,17 @@ classifiers =
packages = fakeredis
install_requires =
packaging
# Minor version updates to redis tend to break fakeredis. If you
# need to use fakeredis with a newer redis, please submit a PR that
# relaxes this restriction and adds it to the Github Actions tests.
redis<=4.2.2
redis<=4.3.1
six>=1.12
sortedcontainers
python_requires = >=3.5
python_requires = >=3.7

[options.extras_require]
lua =
lupa
aioredis =
aioredis

# Tool configurations below here

[flake8]
max-line-length = 119
Expand Down

0 comments on commit 6e07519

Please sign in to comment.