microsoftgraph / microsoftgraph/msgraph-sdk-python

False-positive DeprecationWarning

未关闭
#965 3 条评论 10 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

area:documentation priority:p2
主要语言
Python
星标
630
派生
96
平均合并
15 小时 20 分钟
30 天内合并 PR
3

描述

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_

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从 kiota_abstractions.default_query_parameters.py 开始,并使用提供的 Python 导入命令重现警告。检查已弃用的 request-builder 类如何在类定义期间发出警告,然后验证导入 ClassesRequestBuilder 时不会产生警告,而实例化已弃用的类仍会发出警告。

由索引模型根据 Issue 内容生成。

评估

技术栈
python
领域
api
Issue 类型
缺陷
难度
2/5
预计耗时
1-3 小时
活跃度
停滞
描述清晰度
描述清楚
新手友好度
45/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。