Skip to content

Conversation

@Dt8333
Copy link
Member

@Dt8333 Dt8333 commented Oct 31, 2025


Motivation / 动机

补全声明的过程中发现不少已有的左右脑互博的声明。
万里江山一片红(Error)
计划先初步修正声明,修复部分转换直到Pyright检查完全通过。

Modifications / 改动点

修正错误的声明。
通过静态检查。

Verification Steps / 验证步骤

Screenshots or Test Results / 运行截图或测试结果

Compatibility & Breaking Changes / 兼容性与破坏性变更

  • 这是一个破坏性变更 (Breaking Change)。/ This is a breaking change.
  • 这不是一个破坏性变更。/ This is NOT a breaking change.

Checklist / 检查清单

  • 😊 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。/ If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
  • 👀 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”。/ My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
  • 🤓 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到了 requirements.txtpyproject.toml 文件相应位置。/ I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in requirements.txt and pyproject.toml.
  • 😮 我的更改没有引入恶意代码。/ My changes do not introduce malicious code.

Sourcery 总结

在整个代码库中优化类型注解并修正错误的声明,以解决静态类型检查错误并提高整体类型一致性。

改进点:

  • 在整个代码库中,将已弃用的类型构造 (List, Dict, Optional, Union, Tuple) 替换为内置泛型类型和 PEP 604 联合语法
  • 统一提供者、平台和工具中的方法签名和返回类型,以满足 Pyright 静态分析要求,包括添加 Protocols、类型转换 (casts)、断言 (assertions) 和显式异常路径
  • 通过移除遗留回退机制并依赖更新的 Pillow API,简化 PIL 文本测量
Original summary in English

Summary by Sourcery

Refine type annotations and correct erroneous declarations across the entire codebase to resolve static type-checking errors and improve overall typing consistency.

Enhancements:

  • Replace deprecated typing constructs (List, Dict, Optional, Union, Tuple) with built-in generic types and PEP 604 union syntax throughout the codebase
  • Align method signatures and return types across providers, platforms, and utilities to satisfy Pyright static analysis, including adding Protocols, casts, assertions, and explicit exception paths
  • Simplify PIL text measurement by removing legacy fallback and relying on updated Pillow APIs

@LIghtJUNction
Copy link
Member

LIghtJUNction commented Oct 31, 2025

在整个代码库中,将已弃用的类型构造 (List, Dict, Optional, Union, Tuple) 替换为内置泛型类型和 PEP 604 联合语法

这个其实可以ruff check --fix直接自动修了(这类问题修了3000+处)(详见:#3214

@LIghtJUNction
Copy link
Member

要想用ruff自动修这些问题,需要先启用这些规则才行,目前没启用这些规则,所以没有自动修正

@Dt8333
Copy link
Member Author

Dt8333 commented Oct 31, 2025

那些是precommit修改文件时强行修的。
一个文件只要被修改过就要被pyupgrade按住修一次,不然没法提交(
这个PR本来目的不在那里。

@LIghtJUNction
Copy link
Member

那些是precommit修改文件时强行修的。 不然没法提交( 这个PR本来目的不在那里。

不是,我的意思是ruff check --fix前提是pyproject.toml启用了这些规则,不然就没法自动修复,执行ruff check --fix会告诉你全部通过.

@Dt8333
Copy link
Member Author

Dt8333 commented Oct 31, 2025

在整个代码库中,将已弃用的类型构造 (List, Dict, Optional, Union, Tuple) 替换为内置泛型类型和 PEP 604 联合语法

这个ruff没启用规则目前没修,但是precommit中的pyupgrade在修。
我并没有在手动修复这个。

@LIghtJUNction
Copy link
Member

在整个代码库中,将已弃用的类型构造 (List, Dict, Optional, Union, Tuple) 替换为内置泛型类型和 PEP 604 联合语法

这个ruff没启用规则目前没修,但是precommit中的pyupgrade在修。 我并没有在手动修复这个。

我启用规则然后自动修复的那个pr你看可以直接合并吧,应该没什么问题吧

@LIghtJUNction
Copy link
Member

type hint我之前也打算修过,确实工程量有点大

@Dt8333
Copy link
Member Author

Dt8333 commented Oct 31, 2025

我启用规则然后自动修复的那个pr你看可以直接合并吧,应该没什么问题吧

量有点大
我当入眠读物读读(

@Dt8333 Dt8333 force-pushed the chore-pyright-fix branch from 008ea1f to 11eb0b9 Compare November 1, 2025 09:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants