Cachetools timer with datetime.now
オープン
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 5.1k
- フォーク
- 2.1k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 82
説明
A followup to the issue presented in #6953, I'm running into mypy errors when implementing a cache using the mechanism as defined in the cachetools documentation.
Cachetools documentation for TRLUCache with example that matches the implementation below.
My implementation
def expires_in_ttu(_key, value, now):
expires_in = value[1]
return now + timedelta(seconds=expires_in)
cache = TLRUCache(maxsize=10, ttu=expires_in_ttu, timer=datetime.now)
The mypy error:
Argument "timer" to "TLRUCache" has incompatible type "Callable[[Optional[tzinfo]], datetime]"; expected "Callable[[], float]"
Workaround:
We can use time.monotonic instead of datetime.now, but:
- the example in the docs use datetime.now
- datetime.now is arguably more familiar to most developers
Versions
- cachetools: 5.2.0
- types-cachetools: 5.2.1
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、types-cachetools の TLRUCache の型付けを、ドキュメントにある datetime.now の例および issue #6953 に記載された動作と比較します。記載されているバージョンを使って報告された mypy エラーを再現し、その後、ドキュメントにあるタイマーの使用方法が受け入れられること、またはドキュメントと型付けが一致していることを確認します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- tooling
- issue の種類
- バグ
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100