-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
[CodeStyle][py2] remove six
package (part2)
#47334
[CodeStyle][py2] remove six
package (part2)
#47334
Conversation
你的PR提交成功,感谢你对开源项目的贡献! |
core.update_autotune_status() | ||
return res | ||
except Exception as e: | ||
six.reraise(*sys.exc_info()) |
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.
six
package (part2)six
package (part2)
@@ -27,6 +27,16 @@ def refresh(self): | |||
pass | |||
|
|||
|
|||
class MockKVMetadata: |
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.
可以写一下这个单测修改的思路
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.
嗯嗯,刚刚过完 CI 正准备写一下 😂
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.
上次 PR 修改 API docs 由于直接修改会出问题而回撤的两个,需要额外修改一下才能通过 CI
|
||
def print_prog(prog): | ||
for name, value in sorted(six.iteritems(prog.block(0).vars)): | ||
for name, value in sorted(prog.block(0).vars.items()): |
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.
API docs changes 1:
这里前面不加一个 import
的话从 docstring 提取出来的源码格式会有问题导致无法运行,暂时加了一个 import paddle
了
不过这个问题本地直接用 sampcd_processor.py
提取出来的是正常的,格式不会出问题,不太清楚 CI 上为啥会出问题,暂时没有仔细研究
res = simple_net(x, y) | ||
|
||
exe = paddle.static.Executor(paddle.CPUPlace()) | ||
exe.run(paddle.static.default_startup_program()) | ||
input1 = np.random.random(size=[1,4]).astype('float32') | ||
input2 = np.random.randint(1, 10, size=[1,10], dtype='int64') | ||
input2 = np.random.randint(1, 10, size=[1], dtype='int64') | ||
out = exe.run(paddle.static.default_main_program(), |
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.
API docs changes 2:
CrossEntropyLoss
的 y
shape 为 [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.
关于 six.ensure_str
的修改以及相关 etcd 单测修改的说明
|
||
def cancel_watch(self, watch_id): | ||
pass | ||
|
||
def delete(self, key): | ||
pass | ||
return True |
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.
这里是用于 mock etcd3.Etcd3Client
行为的类,但实际上很多返回数据和真实的 etcd3.Etcd3Client
方法返回数据是不一致的,比如 get
方法实际上返回 tuple[bytes, KVMetadata]
,get_prefix
返回 Iterable[tuple[bytes, KVMetadata]]
,与原来 MockEtcdClient
这两个方法返回数据类型是完全不一致的,这导致了将 six.ensure_str(x)
修改为 x.decode()
单测会报错
因此这里根据 etcd3 文档、源码以及运行时实测的具体数据类型,修改了这里 mock 的数据,其中 KVMetaData
用 mock 的 MockKVMetadata
代替
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.
由于源码里 six.ensure_str
都是对 get
和 get_prefix
返回结果进行操作的,是确定的 bytes 类型,因此相关位置全部修改为了 decode
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.
请 @xymyeah review下[test_fleet_elastic_manager.py]
的修改
@@ -35,28 +45,30 @@ def put(self, key, value, lease=None): | |||
pass | |||
|
|||
def get(self, key): | |||
value = "0" | |||
return value, value | |||
return b'0', MockKVMetadata(b"/prefix") |
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.
之前也是基于etcd3的mock,不修改会有问题是吗?不确定这样修改后是否可以正常运行单测
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.
对的,mock 的数据返回的是 str,而实际应该是 bytes,在原来的代码里使用 six.ensure_str(x)
可以保证这两种都没问题,但如果需要移除 six 的话就需要根据情况判断了,这里我认为返回数据是确定的 bytes 就直接使用 x.decode()
了,但会因为 mock 数据是 str 而出问题
如果修改的风险不可接受,我觉得单独定义一个 _ensure_str
来模拟原来 six.ensure_str
行为,可以保证对代码没有任何影响
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.
这个单测主要是用来mock etcd3,修改后不产生影响就行,其他没啥问题
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.
LGTM
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.
LGTM
PR types
Others
PR changes
Others
Describe
清理
six
模块的第二步(同时也是最后一步)six.reraise
(不修改行为,只是根据情况调整以获得更好的报错信息)raise
raise e
python/paddle/fluid/executor.py
),直接移除six.ensure_str
(类似paddle.compat.to_text
,根据情况修改)six.ensure_str
的参数(即Etcd3Client.get
和Etcd3Client.get_prefix
的返回值) 全都需要 decode,单测里 Mock 的数据是有问题的BUILTIN_LIKELY_MODULES
列表中的six
six
下的函数(如six.iteritems
)全局搜索
import six
/from six
已无残余,搜索 six 也没有相关残余,应当本 PR 即可完全清理Related links
six
part1: [CodeStyle][py2] removesix
package (part1) #46965six
package and__future__
imports in docs docs#5352