-
Notifications
You must be signed in to change notification settings - Fork 5.7k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
[CodeStyle][isort] introduce isort (part5) #48404
Conversation
你的PR提交成功,感谢你对开源项目的贡献! |
a0c42d8
to
eba476f
Compare
@@ -37,5 +37,7 @@ | |||
convert_dtype, | |||
) | |||
from paddle.fluid.layers import fill_constant, utils, scale # noqa: F401 | |||
from paddle.tensor.layer_function_generator import templatedoc # noqa: F401 | |||
from paddle.fluid.layers.layer_function_generator import ( # noqa: F401 |
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.
因为格式化后变化有点多,这里的实际 diff 如下:
# python/paddle/common_ops_import.py
- from paddle.tensor.layer_function_generator import templatedoc # noqa: F401
+ from paddle.fluid.layers.layer_function_generator import ( # noqa: F401
+ templatedoc,
+ )
# python/paddle/tensor/math.py
- from paddle.common_ops_import import templatedoc
+ from .layer_function_generator import templatedoc
因为按照默认排序在 import paddle
时就会报如下错误
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/home/aistudio/Projects/Paddle/build/python/paddle/__init__.py", line 30, in <module>
monkey_patch_variable()
File "/home/aistudio/Projects/Paddle/build/python/paddle/fluid/layers/math_op_patch.py", line 600, in monkey_patch_variable
import paddle.tensor
File "/home/aistudio/Projects/Paddle/build/python/paddle/tensor/__init__.py", line 15, in <module>
from .attribute import is_complex # noqa: F401
File "/home/aistudio/Projects/Paddle/build/python/paddle/tensor/attribute.py", line 24, in <module>
from ..static import Variable
File "/home/aistudio/Projects/Paddle/build/python/paddle/static/__init__.py", line 18, in <module>
from . import nn # noqa: F401
File "/home/aistudio/Projects/Paddle/build/python/paddle/static/nn/__init__.py", line 15, in <module>
from .common import fc # noqa: F401
File "/home/aistudio/Projects/Paddle/build/python/paddle/static/nn/common.py", line 20, in <module>
from paddle.common_ops_import import (
File "/home/aistudio/Projects/Paddle/build/python/paddle/common_ops_import.py", line 40, in <module>
from paddle.tensor.layer_function_generator import templatedoc # noqa: F401
File "/home/aistudio/Projects/Paddle/build/python/paddle/tensor/layer_function_generator.py", line 32, in <module>
from ..static import Variable
貌似是因为有循环依赖 tensor -> static -> common_ops_import -> tensor
,因为这里 common_ops_import
包含一个从 paddle.tensor
import 的函数 templatedoc
(layer_function_generator
里的函数)
这就导致任何 import common_ops_import
的模块都会去 import tensor
,很容易产生循环依赖,因此这里将这个 templatedoc
改为从 fluid.layers
里直接 import 了(tensor
下的 templatedoc
是从 fluid.layers
copy 过来的,内容完全一致)
修改后 common_ops_import 里的全是 fluid 下的 API,可以保证非 fluid 模块引用时不会产生循环依赖
这里用图说明下改动:
Before | After |
---|---|
![]() |
![]() |
之后 common_ops_import 里的 templatedoc 应该会在清理 fluid 的时候就被清理掉了
PR types
Others
PR changes
Others
Describe
引入 isort 第五部分,格式化
python/paddle/tensor
目录及python/paddle/common_ops_import.py
Related links
isort
(part1) #46475