-
Notifications
You must be signed in to change notification settings - Fork 8
feat: config ak/sk... support empty str #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@@ -29,13 +29,22 @@ class Config: | |||
|
|||
def load_config() -> Config: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing function or method docstring (missing-function-docstring)
Details
lint 解释
missing-function-docstring
是一个常见的代码质量检查,用于确保函数或方法有文档字符串(docstring)。文档字符串是用于描述函数、类或模块用途的字符串,通常放在函数定义的第一行。它有助于其他开发者理解代码的功能和使用方式。
错误用法
以下是一个缺少函数文档字符串的示例:
def calculate_area(length, width):
return length * width
在这个例子中,calculate_area
函数没有文档字符串,这可能会导致其他开发者难以理解该函数的作用。
正确用法
以下是添加了文档字符串的正确示例:
def calculate_area(length, width):
"""
计算矩形面积
参数:
length (float): 矩形的长度
width (float): 矩形的宽度
返回:
float: 矩形的面积
"""
return length * width
在这个例子中,calculate_area
函数添加了一个文档字符串,详细描述了函数的功能、参数和返回值。这有助于提高代码的可读性和可维护性。
💡 以上内容由 AI 辅助生成,如有疑问欢迎反馈交流
config.endpoint_url = "YOUR_QINIU_ENDPOINT_URL" | ||
if not config.region_name or len(config.access_key) == 0: | ||
config.region_name = "YOUR_QINIU_REGION_NAME" | ||
|
||
logger.info(f"Configured access_key: {config.access_key}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use lazy % formatting in logging functions (logging-fstring-interpolation)
Details
lint 解释
logging-fstring-interpolation
是一个lint规则,用于检查在日志记录函数中使用懒惰的 %
格式化。这个规则建议使用更现代和易读的格式化方法,如 f-string 或 str.format()
。
错误用法
以下是一个使用 %
格式化的错误示例:
import logging
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)
user_id = 123
logger.debug("User ID: %d" % user_id)
在这个例子中,日志消息使用了 %
格式化方法。
正确用法
以下是一个使用 f-string 的正确示例:
import logging
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)
user_id = 123
logger.debug(f"User ID: {user_id}")
在这个例子中,日志消息使用了 f-string 格式化方法,这是一种更现代和易读的格式化方式。
💡 以上内容由 AI 辅助生成,如有疑问欢迎反馈交流
config.endpoint_url = "YOUR_QINIU_ENDPOINT_URL" | ||
if not config.region_name or len(config.access_key) == 0: | ||
config.region_name = "YOUR_QINIU_REGION_NAME" | ||
|
||
logger.info(f"Configured access_key: {config.access_key}") | ||
logger.info(f"Configured endpoint_url: {config.endpoint_url}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use lazy % formatting in logging functions (logging-fstring-interpolation)
Details
lint 解释
logging-fstring-interpolation
是一个lint规则,用于检查在日志记录函数中使用懒惰的字符串格式化(lazy string formatting)。懒惰的字符串格式化意味着只有在实际需要时才进行字符串格式化,而不是在记录日志时就立即进行。这可以提高性能,特别是在日志级别设置为不记录某些信息时。
错误用法
以下是一个使用非懒惰字符串格式化的示例:
import logging
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)
user_id = 123
username = "john_doe"
logger.debug("User %s logged in with ID %d" % (username, user_id))
在这个例子中,字符串格式化在记录日志时立即进行,即使日志级别设置为不记录 DEBUG
级别的信息。
正确用法
以下是一个使用懒惰字符串格式化的示例:
import logging
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)
user_id = 123
username = "john_doe"
logger.debug("User %s logged in with ID %d" % (username, user_id))
在这个例子中,字符串格式化在记录日志时立即进行,即使日志级别设置为不记录 DEBUG
级别的信息。
错误用法
以下是一个使用非懒惰字符串格式化的示例:
import logging
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)
user_id = 123
username = "john_doe"
logger.debug("User %s logged in with ID %d" % (username, user_id))
在这个例子中,字符串格式化在记录日志时立即进行,即使日志级别设置为不记录 DEBUG
级别的信息。
正确用法
以下是一个使用懒惰字符串格式化的示例:
import logging
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)
user_id = 123
username = "john_doe"
logger.debug("User %s logged in with ID %d" % (username, user_id))
在这个例子中,字符串格式化在记录日志时立即进行,即使日志级别设置为不记录 DEBUG
级别的信息。
💡 以上内容由 AI 辅助生成,如有疑问欢迎反馈交流
config.endpoint_url = "YOUR_QINIU_ENDPOINT_URL" | ||
if not config.region_name or len(config.access_key) == 0: | ||
config.region_name = "YOUR_QINIU_REGION_NAME" | ||
|
||
logger.info(f"Configured access_key: {config.access_key}") | ||
logger.info(f"Configured endpoint_url: {config.endpoint_url}") | ||
logger.info(f"Configured region_name: {config.region_name}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use lazy % formatting in logging functions (logging-fstring-interpolation)
Details
lint 解释
logging-fstring-interpolation
是一个lint规则,用于检查在日志记录函数中使用懒惰的 %
格式化。这个规则建议使用更现代和灵活的字符串格式化方法,如 f-string(格式化字符串字面值),而不是传统的 %
操作符。
错误用法
以下是一个使用 %
操作符进行日志记录的示例:
import logging
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)
user_id = 123
logger.debug("User ID: %d", user_id)
在这个例子中,%d
是一个占位符,用于格式化整数 user_id
。
正确用法
以下是一个使用 f-string 进行日志记录的示例:
import logging
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)
user_id = 123
logger.debug(f"User ID: {user_id}")
在这个例子中,f-string 提供了一种更简洁和易读的方式来格式化字符串。
💡 以上内容由 AI 辅助生成,如有疑问欢迎反馈交流
VERSION = '1.1.1' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Final newline missing (missing-final-newline)
Details
lint 解释
这个lint结果表明在文件的末尾缺少一个换行符(final newline missing)。根据代码风格指南,每个文件应该以一个换行符结束,这样可以确保文件内容不会被其他文本意外地连接在一起。
错误用法
# 这是一个错误的示例,文件末尾没有换行符
def example_function():
print("Hello, World!")
正确用法
# 这是一个正确的示例,文件末尾有一个换行符
def example_function():
print("Hello, World!")
# 注意:在最后一行后面有一个空的换行符
💡 以上内容由 AI 辅助生成,如有疑问欢迎反馈交流
@@ -1,2 +1,2 @@ | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing module docstring (missing-module-docstring)
Details
lint 解释
missing-module-docstring
是一个常见的代码质量检查,用于确保每个模块(即 .py
文件)都有一个文档字符串。文档字符串是位于文件顶部的注释块,通常用三引号括起来,用于描述模块的功能和用途。
错误用法
以下是一个缺少模块文档字符串的示例:
# version.py
def get_version():
return "1.0.0"
在这个例子中,version.py
文件没有包含任何文档字符串。
正确用法
以下是添加了模块文档字符串的正确示例:
"""
This module provides functions related to version management.
"""
def get_version():
"""
Returns the current version of the application.
:return: The version string.
"""
return "1.0.0"
在这个例子中,version.py
文件包含了一个模块文档字符串,并且函数 get_version
也包含了一个文档字符串。
💡 以上内容由 AI 辅助生成,如有疑问欢迎反馈交流
No description provided.