-
Notifications
You must be signed in to change notification settings - Fork 263
Resume upload api default to v2 #460
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
base: master
Are you sure you want to change the base?
Conversation
@@ -10,22 +12,22 @@ | |||
from qiniu.services.storage.upload_progress_recorder import UploadProgressRecorder | |||
|
|||
# for compat to old sdk (<= v7.11.1) | |||
from qiniu.services.storage.legacy import _Resume # noqa | |||
from qiniu.services.storage.legacy import _Resume # noqa | |||
|
|||
|
|||
def put_data( |
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.
Too many arguments (12/5) (too-many-arguments)
Details
lint 解释
这个lint结果表明在代码中某个函数或方法的参数数量超过了推荐的最大值。具体来说,该函数或方法被定义为接受最多5个参数,但实际传递了12个参数。
错误用法
def my_function(arg1, arg2, arg3, arg4, arg5):
# 函数体
my_function(value1, value2, value3, value4, value5, value6, value7, value8, value9, value10, value11, value12)
正确用法
为了遵循最佳实践,可以考虑以下几种方法来解决这个问题:
- 拆分函数:将一个大函数拆分为多个小函数,每个函数负责不同的功能。
- 使用参数对象:创建一个包含所有必要参数的类或字典,并将其作为单个参数传递给函数。
- 默认参数:为一些参数设置默认值,减少调用时需要传递的参数数量。
示例:
class MyFunctionArgs:
def __init__(self, arg1, arg2, arg3, arg4, arg5, arg6=None, arg7=None, arg8=None, arg9=None, arg10=None):
self.arg1 = arg1
self.arg2 = arg2
self.arg3 = arg3
self.arg4 = arg4
self.arg5 = arg5
self.arg6 = arg6
self.arg7 = arg7
self.arg8 = arg8
self.arg9 = arg9
self.arg10 = arg10
def my_function(args):
# 函数体,使用 args.arg1, args.arg2 等访问参数
args = MyFunctionArgs(value1, value2, value3, value4, value5, value6=value6, value7=value7)
my_function(args)
通过这些方法,可以有效地减少函数的参数数量,提高代码的可读性和可维护性。
💡 以上内容由 AI 辅助生成,如有疑问欢迎反馈交流
data, | ||
params=None, | ||
mime_type='application/octet-stream', | ||
check_crc=False, |
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.
Unused argument 'check_crc' (unused-argument)
Details
lint 解释
Unused argument 'check_crc' (unused-argument)
这个lint结果表示在函数或方法的定义中,有一个参数 check_crc
被声明了但没有被使用。这通常意味着这个参数在当前的实现中没有被任何地方调用或处理。
错误用法
def upload_file(file_path, check_crc):
# 这里没有使用 check_crc 参数
with open(file_path, 'rb') as file:
data = file.read()
return data
正确用法
如果你确定 check_crc
参数是不需要的,可以将其从函数定义中移除:
def upload_file(file_path):
# 移除了 unused 的 check_crc 参数
with open(file_path, 'rb') as file:
data = file.read()
return data
如果 check_crc
参数在未来的实现中有用,但目前没有使用,可以考虑添加一个注释来说明为什么这个参数存在:
def upload_file(file_path, check_crc=False):
# 这个参数目前未使用,但将来可能会用到
with open(file_path, 'rb') as file:
data = file.read()
return data
这样可以保持代码的清晰和可维护性。
💡 以上内容由 AI 辅助生成,如有疑问欢迎反馈交流
check_crc=False, | ||
progress_handler=None, | ||
fname=None, | ||
hostscache_dir=None, |
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.
Unused argument 'hostscache_dir' (unused-argument)
Details
lint 解释
Unused argument 'hostscache_dir' (unused-argument)
这个lint结果表示在函数或方法的定义中,有一个参数 hostscache_dir
被声明了但没有被使用。这通常意味着这个参数在函数内部没有被引用,可能是由于代码重构、遗漏或其他原因导致的。
错误用法
def upload_file(file_path, hostscache_dir):
# 这里没有使用 hostscache_dir 参数
with open(file_path, 'rb') as file:
data = file.read()
return data
正确用法
def upload_file(file_path):
# 直接使用文件路径进行上传,不需要额外的参数
with open(file_path, 'rb') as file:
data = file.read()
return data
💡 以上内容由 AI 辅助生成,如有疑问欢迎反馈交流
regions=regions, accelerate_uploading=accelerate_uploading | ||
) | ||
|
||
|
||
@deprecated("use put_file_v2 instead") | ||
def put_file( |
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.
Too many arguments (16/5) (too-many-arguments)
Details
lint 解释
这个lint结果表明在代码中某个函数或方法的参数数量超过了推荐的最大值。具体来说,该函数或方法被定义为接受最多5个参数,但实际传递了16个参数。
错误用法
def my_function(arg1, arg2, arg3, arg4, arg5):
pass
my_function(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16)
正确用法
为了遵循最佳实践,应该尽量减少函数或方法的参数数量。如果确实需要传递多个参数,可以考虑使用字典、列表或其他数据结构来封装这些参数。
def my_function(params):
pass
params = {
'arg1': value1,
'arg2': value2,
'arg3': value3,
'arg4': value4,
'arg5': value5,
# 其他参数...
}
my_function(params)
💡 以上内容由 AI 辅助生成,如有疑问欢迎反馈交流
@@ -1,6 +1,6 @@ | |||
# -*- coding: utf-8 -*- |
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
是一个常见的代码质量检查,用于确保模块(即Python文件)的顶部包含文档字符串(docstring)。文档字符串是用三引号括起来的字符串,通常位于模块、类或函数的开头,用于描述其用途和功能。
错误用法
以下是一个缺少模块文档字符串的示例:
# upload_pfops.py
def upload_file(file_path):
"""Uploads a file to the server."""
# 函数实现
在这个例子中,upload_pfops.py
文件没有包含任何文档字符串。
正确用法
以下是一个包含模块文档字符串的示例:
# upload_pfops.py
"""
This module provides functions for uploading files to a server.
"""
def upload_file(file_path):
"""Uploads a file to the server."""
# 函数实现
在这个例子中,upload_pfops.py
文件顶部包含了一个模块文档字符串,描述了该模块的用途。
💡 以上内容由 AI 辅助生成,如有疑问欢迎反馈交流
@@ -1,6 +1,6 @@ | |||
# -*- coding: utf-8 -*- | |||
# flake8: noqa | |||
from qiniu import Auth, put_file, urlsafe_base64_encode | |||
from qiniu import Auth, urlsafe_base64_encode, put_file_v2 | |||
|
|||
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.
Constant name "access_key" doesn't conform to UPPER_CASE naming style (invalid-name)
Details
lint 解释
这个lint结果表明在代码中定义了一个常量 access_key
,但它的命名风格不符合Python的PEP 8规范。根据PEP 8规范,常量名称应该全部使用大写字母,并用下划线分隔单词。
错误用法
access_key = "your_access_key_here"
正确用法
ACCESS_KEY = "your_access_key_here"
💡 以上内容由 AI 辅助生成,如有疑问欢迎反馈交流
@@ -1,6 +1,6 @@ | |||
# -*- coding: utf-8 -*- | |||
# flake8: noqa | |||
from qiniu import Auth, put_file, urlsafe_base64_encode | |||
from qiniu import Auth, urlsafe_base64_encode, put_file_v2 | |||
|
|||
access_key = '...' | |||
secret_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.
Constant name "secret_key" doesn't conform to UPPER_CASE naming style (invalid-name)
Details
lint 解释
这个lint结果表明在代码中定义了一个常量 secret_key
,但它的命名风格不符合Python的PEP 8规范。根据PEP 8规范,常量名称应该全部使用大写字母,并用下划线分隔单词。
错误用法
# 错误示例:常量名称未遵循UPPER_CASE命名风格
secret_key = 'my_secret_key'
正确用法
# 正确示例:常量名称遵循UPPER_CASE命名风格
SECRET_KEY = 'my_secret_key'
💡 以上内容由 AI 辅助生成,如有疑问欢迎反馈交流
@@ -33,6 +33,6 @@ | |||
|
|||
localfile = './python_video.flv' |
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.
Constant name "localfile" doesn't conform to UPPER_CASE naming style (invalid-name)
Details
lint 解释
这个lint结果表明在代码中定义了一个常量 localfile
,但它的命名风格不符合Python的PEP 8规范。根据PEP 8规范,常量名称应该全部使用大写字母,并用下划线分隔单词。
错误用法
# 错误示例:常量名称未遵循UPPER_CASE命名风格
localfile = "path/to/local/file"
正确用法
# 正确示例:常量名称遵循UPPER_CASE命名风格
LOCAL_FILE_PATH = "path/to/local/file"
💡 以上内容由 AI 辅助生成,如有疑问欢迎反馈交流
regions=regions, accelerate_uploading=accelerate_uploading | ||
) | ||
|
||
|
||
@deprecated("use put_file_v2 instead") | ||
def put_file( |
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.
Too many local variables (16/15) (too-many-locals)
Details
lint 解释
这个lint结果表明在代码文件 uploader.py
中,某个函数或方法的局部变量数量超过了推荐的最大值(15个)。过多的局部变量可能会导致代码难以阅读和维护。
错误用法
以下是一个示例代码片段,展示了可能导致“too-many-locals” lint错误的不正确用法:
def upload_file(file_path, bucket_name, access_key, secret_key, region, storage_class, encryption_type, versioning_enabled, lifecycle_policy, tags):
# 这里定义了16个局部变量
local_var1 = file_path
local_var2 = bucket_name
local_var3 = access_key
local_var4 = secret_key
local_var5 = region
local_var6 = storage_class
local_var7 = encryption_type
local_var8 = versioning_enabled
local_var9 = lifecycle_policy
local_var10 = tags
local_var11 = "additional_variable"
local_var12 = "another_additional_variable"
local_var13 = "yet_another_additional_variable"
local_var14 = "one_more_additional_variable"
local_var15 = "and_one_last_additional_variable"
local_var16 = "too_many_variables" # 这个变量导致了lint错误
正确用法
以下是一个示例代码片段,展示了如何通过重构代码来减少局部变量的数量:
def upload_file(file_path, bucket_name, access_key, secret_key, region, storage_class, encryption_type, versioning_enabled, lifecycle_policy, tags):
# 通过将多个参数组合成一个字典来减少局部变量数量
file_info = {
'file_path': file_path,
'bucket_name': bucket_name,
'access_key': access_key,
'secret_key': secret_key,
'region': region,
'storage_class': storage_class,
'encryption_type': encryption_type,
'versioning_enabled': versioning_enabled,
'lifecycle_policy': lifecycle_policy,
'tags': tags
}
# 使用字典中的键来访问值,而不是定义多个局部变量
local_var1 = file_info['file_path']
local_var2 = file_info['bucket_name']
local_var3 = file_info['access_key']
local_var4 = file_info['secret_key']
local_var5 = file_info['region']
local_var6 = file_info['storage_class']
local_var7 = file_info['encryption_type']
local_var8 = file_info['versioning_enabled']
local_var9 = file_info['lifecycle_policy']
local_var10 = file_info['tags']
local_var11 = "additional_variable"
local_var12 = "another_additional_variable"
local_var13 = "yet_another_additional_variable"
local_var14 = "one_more_additional_variable"
local_var15 = "and_one_last_additional_variable"
通过这种方式,可以有效地减少局部变量的数量,从而避免“too-many-locals” lint错误。
💡 以上内容由 AI 辅助生成,如有疑问欢迎反馈交流
) | ||
|
||
|
||
def put_file_v2( |
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.
Too many arguments (15/5) (too-many-arguments)
Details
lint 解释
这个lint结果表明在代码中某个函数或方法的参数数量超过了推荐的最大值。具体来说,该函数或方法被定义为接受最多5个参数,但实际传递了15个参数。
错误用法
def process_data(a, b, c, d, e):
# 函数体
process_data(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15)
正确用法
为了遵循最佳实践,可以考虑以下几种方法来减少参数数量:
-
使用字典或列表:将多个相关的参数打包成一个字典或列表传递。
def process_data(data): # 函数体 a = data['a'] b = data['b'] c = data['c'] d = data['d'] e = data['e'] data = { 'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5, 'f': 6, 'g': 7, 'h': 8, 'i': 9, 'j': 10, 'k': 11, 'l': 12, 'm': 13, 'n': 14, 'o': 15 } process_data(data)
-
使用多个函数:将不同的逻辑拆分成多个函数,每个函数处理一组参数。
def process_first_five(a, b, c, d, e): # 处理前五个参数 def process_next_ten(f, g, h, i, j, k, l, m, n, o): # 处理接下来的十个参数 process_first_five(1, 2, 3, 4, 5) process_next_ten(6, 7, 8, 9, 10, 11, 12, 13, 14, 15)
-
使用默认参数:为函数参数设置默认值,减少调用时需要传递的参数数量。
def process_data(a, b, c, d=0, e=0): # 函数体 process_data(1, 2, 3)
通过这些方法,可以有效地减少函数或方法的参数数量,提高代码的可读性和可维护性。
💡 以上内容由 AI 辅助生成,如有疑问欢迎反馈交流
KODO-22065