False-positive DeprecationWarning

未關閉
#965 3 則留言 10 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

評估

難度
2/5
預估耗時
1-3 小時
新手友好度
45/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
停滯
技術堆疊
python
領域
api

研究方向

從 kiota_abstractions.default_query_parameters.py 開始,並使用提供的 Python 匯入命令重現警告。檢查已棄用的 request-builder 類別如何在類別定義期間發出警告,然後驗證匯入 ClassesRequestBuilder 時不會產生警告,而實例化已棄用的類別仍會發出警告。

由索引模型根據 Issue 內容生成。

描述

area:documentation priority:p2
Describe the bug

Simply just importing one of the class request builders is enough to trigger a deprecation warnings. The reproduction steps below will output 3 different deprecation warnings, even though the deprecated classes are not being used.

This is because the warnings are in the class scope, so will be ran at "compile" time.
Changing the first example to the second will only warn when the dataclass is instantiated.

# kiota_abstractions.default_query_parameters.py
@dataclass
class GetQueryParameters(QueryParameters):
    """
    Default placeholder class for query parameters.
    """
    warn("GetQueryParameters is deprecated. Use QueryParameters instead.", DeprecationWarning)
# kiota_abstractions.default_query_parameters.py
@dataclass
class GetQueryParameters(QueryParameters):
    """
    Default placeholder class for query parameters.
    """
    def __init__(self, *args, **kwargs):
        warn("GetQueryParameters is deprecated. Use QueryParameters instead.", DeprecationWarning)
        super().__init__(*args, **kwargs)
Expected behavior

Deprecation warnings are only raised when you instantiate a deprecated class I.E. are actually using it, not just importing it.

How to reproduce

python -Wd -c "from msgraph.generated.education.classes.classes_request_builder import ClassesRequestBuilder"

SDK Version

1.12.0

Latest version known to work for scenario above?

No response

Known Workarounds

Only workaround is to suppress deprecation warnings from this library.

import warnings

warnings.filterwarnings("ignore", module="msgraph", category=DeprecationWarning)
warnings.filterwarnings(
    "ignore",
    module="kiota_abstractions",
    category=DeprecationWarning,
)
Debug output
Click to expand log ```
</details>


### Configuration

_No response_

### Other information

_No response_
主要語言
Python
星號
630
分支
96
平均合併
15 小時 20 分鐘
30 天內合併 PR
3

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

microsoftgraph/msgraph-sdk-python 的其他 Issue

查看 microsoftgraph/msgraph-sdk-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。