From dc38df7a06524f499effb11c58d2703aa3fce2bc Mon Sep 17 00:00:00 2001 From: qiang1218 <18792451160@163.com> Date: Thu, 29 Jun 2023 14:54:42 +0800 Subject: [PATCH] =?UTF-8?q?style:=20=E6=A0=BC=E5=BC=8F=E5=8C=96=E6=96=87?= =?UTF-8?q?=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/standard/language_rules.md | 5 +++-- docs/standard/style_rules.md | 6 ++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/docs/standard/language_rules.md b/docs/standard/language_rules.md index 4d0360a..f8a0c5b 100644 --- a/docs/standard/language_rules.md +++ b/docs/standard/language_rules.md @@ -107,7 +107,7 @@ echo.EchoFilter(input, output, delay=0.7, atten=4) - [typing](https://google.github.io/styleguide/pyguide.html#typing-imports) - [collections.abc](https://google.github.io/styleguide/pyguide.html#typing-imports) - - [typing_extensions](https://github.com/python/typing_extensions/blob/main/README.md) + - [typing_extensions](https://github.com/python/typing_extensions/blob/main/README.md) - 重定向模块 [Six.moves](https://six.readthedocs.io/#module-six.moves) @@ -184,7 +184,7 @@ echo.EchoFilter(input, output, delay=0.7, atten=4) - 如果有必要,请使用内置异常类。例如,抛出 `ValureError` 来指示编程错误。比如违反了前置条件(需要一个正数,但传递了一个负数)。不要使用 `assert` 语句验证公共 API 的参数值。`assert` - 用于确保内部正确性,不得强制使用,也不表示发生了某些意外事件。如果在后一种情况下需要使用异常,请使用 raise 语句。例如: + 用于确保内部正确性,不得强制使用,也不表示发生了某些意外事件。如果在后一种情况下需要使用异常,请使用 raise 语句。例如: !!! success "推荐" @@ -842,6 +842,7 @@ Python 是一种异常灵活的语言,它为你提供了很多花哨的特性 推荐使用 `from __future__ import` 语句。所有的新代码都应该包含以下内容,现有的代码也应该在有条件的情况下进行兼容更新。 在 3.5 版本(而不是 >= 3.7)上执行的代码中,导入: + ```python from __future__ import generator_stop ``` diff --git a/docs/standard/style_rules.md b/docs/standard/style_rules.md index 3988331..4ede3c8 100644 --- a/docs/standard/style_rules.md +++ b/docs/standard/style_rules.md @@ -1438,7 +1438,8 @@ def deals_with_text_data(x: str) -> str: def deals_with_binary_data(x: bytes) -> bytes: ... ``` -如果函数的所有字符串类型始终相同,例如,如果返回类型与上面代码中的参数类型相同,请使用 + +如果函数的所有字符串类型始终相同,例如,如果返回类型与上面代码中的参数类型相同,请使用 [AnyStr](https://google.github.io/styleguide/pyguide.html#typing-type-var)。 想要正确的标注字符串类型,取决于代码将使用哪个版本的 Python 。 @@ -1459,7 +1460,7 @@ Python 代码中去定义(无论是否有类型)。如果模块中的类型 from typing import Any as AnyType ``` -推荐使用内置类型作为注释(如果可用)。 Python 通过 Python 3.9 中引入的 [PEP-585](https://peps.python.org/pep-0585/) +推荐使用内置类型作为注释(如果可用)。 Python 通过 Python 3.9 中引入的 [PEP-585](https://peps.python.org/pep-0585/) 支持使用参数容器类型的类型注释。 ```python @@ -1468,6 +1469,7 @@ def generate_foo_scores(foo: set[str]) -> list[float]: ``` 注意:[Apache Beam](https://github.com/apache/beam/issues/23366) 的用户应继续通过输入导入参数容器。 + ```python from typing import Set, List