Search code examples
pythonpython-typingmypy

Missing type parameters for generic type "StrictRedis"


import redis

a = redis.StrictRedis(host="a", port=123, db=0, decode_response=true)

Mypy is giving error Missing type parameters for generic type "StrictRedis" [type-arg]

Python version: 3.9.20

Mypy version: 1.14.1


Solution

  • This is a type warning you can theoretically ignore. The types-redis extension that is part of typeshed that your type-checker is using, defines Redis as a Generic bound over str | bytes.
    This is done to better know the outputs or inputs of some method, e.g. of pipeline -> str | bytes or register_script(script: str | bytes) -> Script.

    You should init it as:

    a = redis.StrictRedis[your-type-here](host="a", port=123, db=0, decode_response=true)
    

    If you do not know which to use, use redis.StrictRedis[str | bytes](... or just add a # type: ignore[type-arg]