[Dy2St] skip compare between func and module attribute to fix NumPy 1.25 error #55482
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR types
Others
PR changes
Others
Description
在 NumPy 1.25 后在一些错误的比较时会直接报错1,比如
原来在 NumPy 1.24 会报 Warning 的比较现在直接报错了
我们动转静的
is_unsupported
用于判断一个函数是否不需要转写,其实现是将所有跳过的模块所有成员与当前函数进行比较(==
也即__eq__
),而 NumPy 中包含成员np.False_
,由于np.False_
重载了__eq__
,因此其比较行为是可能报错的目前报错是发生在嵌套
Sequential
与np.False_
比较时出现的问题,比如layer[0]
是两层的,layer[1]
是一层的,其实和[[1, 2], 3]
是同样的结构,在 Python 1.25 就会报错Workaround
跳过与属性的比较,只和函数比较,按理说传入的是 callable 的,那么也没有必要和非 callable 进行比较,函数比较直接
is
即可,下面的if isinstance(func_in_dict, (list, numpy.ndarray))
看起来也是没有必要的了(和 #27631、#34246 相关)PCard-66972
Footnotes
NumPy 1.25 Release Notes - Expired deprecations ↩