Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mypy reports incompatible type in rate limiters #88

Closed
russellcardullo opened this issue Jan 6, 2022 · 7 comments
Closed

mypy reports incompatible type in rate limiters #88

russellcardullo opened this issue Jan 6, 2022 · 7 comments

Comments

@russellcardullo
Copy link

russellcardullo commented Jan 6, 2022

Hello! I've recently updated one of my projects from limits 2.0.3 to 2.1.1 and ran into an issue where mypy reports incompatible types for MovingWindowRateLimiter and FixedWindowRateLimiter. A minimal reproducer:

import limits

storage = limits.storage.storage_from_string("memory://")
strategy = limits.strategies.MovingWindowRateLimiter(storage)

With this file and running mypy 0.930 I get:

error: Argument 1 to "MovingWindowRateLimiter" has incompatible type "Union[limits.storage.base.Storage, limits.aio.storage.base.Storage]"; expected "limits.storage.base.Storage"

I could also reproduce that by running mypy on the tests in this repo: python3 -m mypy tests/test_strategy.py.

Any ideas what I could look at next?

Thanks!

@alisaifee
Copy link
Owner

Looks like this is just a bug introduced by storage_from_string returning either the aio or sync version of the storage.

@alisaifee
Copy link
Owner

Could you try this commit to see if it resolves the issue? 4265c71

@alisaifee
Copy link
Owner

Should be resolved in 2.2.0

@alisaifee alisaifee reopened this Jan 6, 2022
@russellcardullo
Copy link
Author

Thanks! Just confirmed 2.2.0 fixes it.

@russellcardullo
Copy link
Author

Hi! I've started seeing this again starting in version 2.5.2 and all newer versions. I used the same reproducer in the description and got:

error: Argument 1 to "MovingWindowRateLimiter" has incompatible type "Union[limits.storage.base.Storage, limits.aio.storage.base.Storage]"; expected "limits.storage.base.Storage"

Tried 2.5.1 and the problem went away.

@alisaifee alisaifee reopened this Apr 26, 2022
@alisaifee
Copy link
Owner

Ouch, sorry about that. 2.5.2 was actually supposed to improve type safety 😿

alisaifee added a commit that referenced this issue Apr 26, 2022
alisaifee added a commit that referenced this issue Apr 26, 2022
@alisaifee
Copy link
Owner

Fixed in 2.5.4 and 2.6.1. Sorry about the regression.

netbsd-srcmastr referenced this issue in NetBSD/pkgsrc Oct 21, 2022
v2.7.1
------
Release Date: 2022-10-20

* Compatibility Updates

  * Increase pymemcached dependency range to in include 4.x
  * Add python 3.11 rc2 to CI


v2.7.0
------
Release Date: 2022-07-16

* Compatibility Updates

  * Update :pypi:`coredis` requirements to include 4.x versions
  * Remove CI / support for redis < 6.0
  * Remove python 3.7 from CI
  * Add redis 7.0 in CI

v2.6.3
------
Release Date: 2022-06-05

* Chores

  * Update development dependencies
  * Add CI for python 3.11
  * Increase test coverage for redis sentinel

v2.6.2
------
Release Date: 2022-05-12

* Compatibility Updates

  * Update :pypi:`motor` requirements to include 3.x version
  * Update async redis sentinel implementation to remove use of deprecated methods.
  * Fix compatibility issue with asyncio redis ``reset`` method in cluster mode
    when used with :pypi:`coredis` versions >= 3.5.0

v2.6.1
------
Release Date: 2022-04-25

* Bug Fix

  * Fix typing regression with strategy constructors `Issue 88 <https://github.com/alisaifee/limits/issues/88>`_


v2.6.0
------
Release Date: 2022-04-25

* Deprecation

  * Removed tests for rediscluster using the :pypi:`redis-py-cluster` library

* Bug Fix

  * Fix incorrect ``__slots__`` declaration in :class:`limits.RateLimitItem`
    and it's subclasses

v2.5.4
------
Release Date: 2022-04-25

* Bug Fix

  * Fix typing regression with strategy constructors `Issue 88 <https://github.com/alisaifee/limits/issues/88>`_

v2.5.3
------
Release Date: 2022-04-22

* Chore

  * Automate Github releases

v2.5.2
------
Release Date: 2022-04-17

* Chore

  * Increase strictness of type checking and annotations
  * Ensure installations from source distributions are PEP-561
    compliant

v2.5.1
------
Release Date: 2022-04-15

* Chore

  * Ensure storage reset methods have consistent signature

v2.5.0
------
Release Date: 2022-04-13

* Feature

  * Add support for using redis cluster via the official redis client
  * Update coredis dependency to use 3.x

* Deprecations

  * Deprecate using redis-py-cluster

* Chores

  * Remove beta tags for async support
  * Update code base to remove legacy syntax
  * Tighten up CI test dependencies

v2.4.0
------
Release Date: 2022-03-10

* Feature

  * Allow passing an explicit connection pool to redis storage.
    Addresses `Issue 77 <https://github.com/alisaifee/limits/issues/77>`_

v2.3.3
------
Release Date: 2022-02-03

* Feature

  * Add support for dns seed list when using mongodb

v2.3.2
------
Release Date: 2022-01-30

* Chores

  * Improve authentication tests for redis
  * Update documentation theme
  * Pin pip version for CI

v2.3.1
------
Release Date: 2022-01-21

* Bug fix

  * Fix backward incompatible change that separated sentinel
    and connection args for redis sentinel (introduced in 2.1.0).
    Addresses `Issue 97 <https://github.com/alisaifee/limits/issues/97>`_


v2.3.0
------
Release Date: 2022-01-15

* Feature

  * Add support for custom cost per hit

* Bug fix

  * Fix installation issues with missing setuptools

v2.2.0
------
Release Date: 2022-01-05

* Feature

  * Enable async redis for python 3.10 via coredis

* Chore

  * Fix typing issue with strategy constructors

v2.1.1
------
Release Date: 2022-01-02

* Feature

  * Enable async memcache for python 3.10

* Bug fix

  * Ensure window expiry is reported in local time for mongodb
  * Fix inconsistent expiry for fixed window with memcached

* Chore

  * Improve strategy tests

v2.1.0
------
Release Date: 2021-12-22

* Feature

  * Add beta asyncio support
  * Add beta mongodb support
  * Add option to install with extras for different storages

* Bug fix

  * Fix custom option for cluster client in memcached
  * Fix separation of sentinel & connection args in :class:`limits.storage.RedisSentinelStorage`

* Deprecation

  * Deprecate GAEMemcached support
  * Remove use of unused `no_add` argument in :meth:`limits.storage.MovingWindowSupport.acquire_entry`

* Chore

  * Documentation theme upgrades
  * Code linting
  * Add compatibility CI workflow



v2.0.3
------
Release Date: 2021-11-28

* Chore

  * Ensure package is marked PEP-561 compliant

v2.0.1
------
Release Date: 2021-11-28

* Chore

  * Added type annotations

v2.0.0
------
Release Date: 2021-11-27

* Chore

  * Drop support for python < 3.7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants