python / python/typeshed

Cachetools timer with datetime.now

オープン
#8,459 コメント 2 件 リアクション 1 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

主要言語
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

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず、types-cachetools の TLRUCache の型付けを、ドキュメントにある datetime.now の例および issue #6953 に記載された動作と比較します。記載されているバージョンを使って報告された mypy エラーを再現し、その後、ドキュメントにあるタイマーの使用方法が受け入れられること、またはドキュメントと型付けが一致していることを確認します。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
tooling
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。