"TypeError: Argument of type 'Bucket' cannot be assigned to parameter of type 'Bucket' in b2sdk.v2"

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

メンテナーはふだん 1 日以内に返信

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

評価

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

調査の方向性

Start with the v2 re-exports in the b2sdk/v2 package and the Bucket class it exposes, then compare them with the implementation under b2sdk/_internal. Check whether B2Api.get_bucket_by_name() returns the same class the public Bucket name points to, and reproduce the ls(latest_only=True) call. Done means the returned object passes the b2.Bucket annotation and ls() runs, or the import path that causes the mismatch is documented. Read the four comments first, since the maintainers may already have explained the cause.

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

説明

more-information-needed
Issue Description

When attempting to use the ls() method on a Bucket object obtained from b2sdk.v2.B2Api.get_bucket_by_name(), I encountered a TypeError stating that the Bucket argument type is incompatible with the expected 'Bucket' parameter type. It appears that get_bucket_by_name() may be returning an internal SDK type not intended for direct use, despite being accessed through the public API.

Steps to Reproduce
  1. Setup a basic environment with b2sdk.v2 configured with valid Backblaze B2 credentials.
  2. Fetch a Bucket using B2Api.get_bucket_by_name().
  3. Attempt to list directories or files using the Bucket.ls() method.
  4. Observe the TypeError related to incompatible type assignment.
Expected Behavior

The Bucket object returned from get_bucket_by_name() should be fully compatible with other methods expecting a Bucket type as defined in the b2sdk.v2 public API.

Actual Behavior

A TypeError is raised suggesting type incompatibility, indicating possible exposure of internal types in what should be a public API method.

Environment
  • Python version: 3.12
  • b2sdk version: 2.1
Additional Context

This issue seems to stem from recent changes in the SDK where non-api packages were moved to b2sdk._internal as noted in the changelog for version 2.0.0. It would be helpful to confirm whether get_bucket_by_name() should return a type from b2sdk.v2 or if there's a recommended workaround for this type mismatch.

import b2sdk.v2 as b2

def get_bucket():
    info = b2.InMemoryAccountInfo()
    b2_api = b2.B2Api(info)
    b2_api.authorize_account("production", settings.BACKBLAZE_KEY_ID, settings.BACKBLAZE_APPLICATION_KEY)
    return b2_api.get_bucket_by_name(settings.BACKBLAZE_BUCKET_NAME)

def list_directories(bucket: b2.Bucket):
    try:
        for file_version, folder_name in bucket.ls(latest_only=True):
            print(folder_name)
    except TypeError as e:
        print(f"TypeError: {str(e)}")

# Example
bucket = get_bucket()
list_directories(bucket)
主要言語
Python
スター
214
フォーク
68
平均マージ
51分
マージ済み PR(30日)
6

環境構築

はじめの一歩

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

Backblaze/b2-sdk-python のほかの issue

Backblaze/b2-sdk-python の issue をすべて見る

似ている issue

Python の issue をもっと見る

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

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