Fix pyrefly\set_linter\stabel_shim_version_linter error

Co-authored-by: huangjingwei<huangjingwei4@huawei.com>



# message auto-generated for no-merge-commit merge:
!35516 merge code_check_fix into master

Fix pyrefly\set_linter\stabel_shim_version_linter error

Created-by: huangjingwei
Commit-by: huangjingwei
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->

# 【合入来源】
> <font color="red">**如有社区issue,请关联issue链接**</font>\
> <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font>

- [ ] 需求
- [ ] 问题单
- [x] issue/工单
- [ ] 重构优化
- [ ] 资料更新

# 【修改方案】

1. pyrefly的检查目录调整,
2. 修复set_linter检查报错。
3. 修复stable_shim_version_linter.py检查的分支。

# 【资料变更】
不涉及

# 【接口变更】
不涉及

# 【功能验证】

pyrefly功能:
![image.png](https://raw.gitcode.com/user-images/assets/7404318/79754ed4-4724-4503-8af9-4780e7c0bee8/image.png 'image.png')
set_linter功能:
![image.png](https://raw.gitcode.com/user-images/assets/7404318/d20565a7-b6d5-48c2-8e06-889f83a3be15/image.png 'image.png')
stable_shim_version功能:
![image.png](https://raw.gitcode.com/user-images/assets/7404318/eb5ad135-72f5-483c-91ad-804d9548c2ff/image.png 'image.png')

# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]

- [ ] 代码注释完备,正确记录错误日志
- [ ] 代码实现进行了返回值、空指针等校验
- [ ] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [ ] PR持续集成流水线(CI)执行通过,代码检查无异常


See merge request: Ascend/pytorch!35516
This commit is contained in:
huangjingwei
2026-05-13 17:24:32 +08:00
committed by ascend-robot
parent aa174c0708
commit a673bcc673
3 changed files with 60 additions and 50 deletions
+43 -41
View File
@@ -3,7 +3,9 @@
python-version = "3.12"
project-includes = [
"torch",
"torch_npu",
"torchnpugen",
"test",
"caffe2",
"test/test_bundled_images.py",
"test/test_bundled_inputs.py",
@@ -21,45 +23,45 @@ project-includes = [
]
project-excludes = [
"tools/**",
"torch/_inductor/runtime/triton_heuristics.py",
"torch/_inductor/runtime/triton_helpers.py",
"torch/_inductor/runtime/halide_helpers.py",
"torch/utils/data/typing.ipynb",
"torch/utils/data/dataframes_pipes.ipynb",
"torch/utils/data/standard_pipes.ipynb",
"torch/onnx/_internal/exporter/_torchlib/ops/nn.py",
"torch/include/**",
"torch/csrc/**",
"torch/distributed/elastic/agent/server/api.py",
"torch/testing/_internal/**",
"torch/distributed/fsdp/fully_sharded_data_parallel.py",
"torch/ao/quantization/pt2e/_affine_quantization.py",
"torch/nn/modules/pooling.py",
"torch/nn/parallel/_functions.py",
"torch/_appdirs.py",
"torch/multiprocessing/pool.py",
"torch/overrides.py",
"torch_npu/_inductor/runtime/triton_heuristics.py",
"torch_npu/_inductor/runtime/triton_helpers.py",
"torch_npu/_inductor/runtime/halide_helpers.py",
"torch_npu/utils/data/typing.ipynb",
"torch_npu/utils/data/dataframes_pipes.ipynb",
"torch_npu/utils/data/standard_pipes.ipynb",
"torch_npu/onnx/_internal/exporter/_torchlib/ops/nn.py",
"torch_npu/include/**",
"torch_npu/csrc/**",
"torch_npu/distributed/elastic/agent/server/api.py",
"torch_npu/testing/_internal/**",
"torch_npu/distributed/fsdp/fully_sharded_data_parallel.py",
"torch_npu/ao/quantization/pt2e/_affine_quantization.py",
"torch_npu/nn/modules/pooling.py",
"torch_npu/nn/parallel/_functions.py",
"torch_npu/_appdirs.py",
"torch_npu/multiprocessing/pool.py",
"torch_npu/overrides.py",
"*/__pycache__/**",
"*/.*",
"torch/_inductor/kernel/vendored_templates/cutedsl/kernels/**",
"torch/_inductor/kernel/vendored_templates/cutedsl/dense_blockscaled_gemm_persistent.py",
"torch_npu/_inductor/kernel/vendored_templates/cutedsl/kernels/**",
"torch_npu/_inductor/kernel/vendored_templates/cutedsl/dense_blockscaled_gemm_persistent.py",
]
ignore-missing-imports = [
# XPU memory symbols not present for builds without XPU support
"torch._C._xpu_beginAllocateCurrentThreadToPool",
"torch._C._xpu_endAllocateToPool",
"torch._C._xpu_releasePool",
"torch._C._xpu_XPUAllocator",
"torch._C._XPUMemPool",
"torch._C._StaticXpuLauncher",
"torch._C._jit_tree_views.*",
"torch.for_onnx.onnx.*",
"torch.ao.quantization.experimental.apot_utils.*",
"torch.ao.quantization.experimental.quantizer.*",
"torch.ao.quantization.experimental.observer.*",
"torch.ao.quantization.experimental.APoT_tensor.*",
"torch.ao.quantization.experimental.fake_quantize_function.*",
"torch.ao.quantization.experimental.fake_quantize.*",
"torch_npu._C._xpu_beginAllocateCurrentThreadToPool",
"torch_npu._C._xpu_endAllocateToPool",
"torch_npu._C._xpu_releasePool",
"torch_npu._C._xpu_XPUAllocator",
"torch_npu._C._XPUMemPool",
"torch_npu._C._StaticXpuLauncher",
"torch_npu._C._jit_tree_views.*",
"torch_npu.for_onnx.onnx.*",
"torch_npu.ao.quantization.experimental.apot_utils.*",
"torch_npu.ao.quantization.experimental.quantizer.*",
"torch_npu.ao.quantization.experimental.observer.*",
"torch_npu.ao.quantization.experimental.APoT_tensor.*",
"torch_npu.ao.quantization.experimental.fake_quantize_function.*",
"torch_npu.ao.quantization.experimental.fake_quantize.*",
"triton.*",
"tensorflow.*",
"tensorboard.*",
@@ -103,8 +105,8 @@ ignore-missing-imports = [
"deeplearning.*",
"einops.*",
"libfb.*",
"torch.fb.*",
"torch.*.fb.*",
"torch_npu.fb.*",
"torch_npu.*.fb.*",
"torch_xla.*",
"onnx.*",
"onnxruntime.*",
@@ -133,7 +135,7 @@ search-path = ["tools/experimental"]
# Dynamo sub-config - note, we experiment with stricter typing here
[[sub-config]]
matches = "torch/_dynamo/**"
matches = "torch_npu/_dynamo/**"
[sub-config.errors]
implicit-import = false
implicit-any = true
@@ -143,19 +145,19 @@ implicit-any = true
# unannotated-return=true
[[sub-config]]
matches = "torch/_dispatch/**"
matches = "torch_npu/_dispatch/**"
[sub-config.errors]
implicit-import = false
implicit-any = true
[[sub-config]]
matches = "torch/_subclasses/**"
matches = "torch_npu/_subclasses/**"
[sub-config.errors]
implicit-import = false
implicit-any = true
[[sub-config]]
matches = "torch/_functorch/**"
matches = "torch_npu/_functorch/**"
[sub-config.errors]
implicit-import = false
implicit-any = true
+13 -5
View File
@@ -12,12 +12,16 @@ BRACKETS = {"{": "}", "(": ")", "[": "]"}
BRACKETS_INV = {j: i for i, j in BRACKETS.items()}
_FSTRING_SENTINEL = ("__fstring_start__",)
def bracket_pairs(tokens: Sequence[TokenInfo]) -> dict[int, int]:
"""Returns a dictionary mapping opening to closing brackets"""
braces: dict[int, int] = {}
stack: list[int] = []
stack: list[object] = []
in_fstring = False
t: TokenInfo | None = None
for i, t in enumerate(tokens):
if t.type == token.OP and not in_fstring:
if t.string in BRACKETS:
@@ -26,20 +30,24 @@ def bracket_pairs(tokens: Sequence[TokenInfo]) -> dict[int, int]:
if not stack:
raise ParseError(t, "Never opened")
begin = stack.pop()
if not isinstance(begin, int) or not 0 <= begin < len(tokens):
raise ParseError(t, f"Mismatched braces at {begin}")
if not (stack and stack[-1] == FSTRING_START):
if not (stack and stack[-1] is _FSTRING_SENTINEL):
braces[begin] = i
b = tokens[begin].string
if b != inv:
raise ParseError(t, f"Mismatched braces '{b}' at {begin}")
elif t.type == FSTRING_START:
stack.append(FSTRING_START)
stack.append(_FSTRING_SENTINEL)
in_fstring = True
elif t.type == FSTRING_END:
if stack.pop() != FSTRING_START:
if not stack or stack.pop() is not _FSTRING_SENTINEL:
raise ParseError(t, "Mismatched FSTRING_START/FSTRING_END")
in_fstring = False
if stack:
raise ParseError(t, "Left open")
raise ParseError(
t if t is not None else tokens[-1], "Left open"
)
return braces
@@ -245,7 +245,7 @@ def get_added_lines(filename: str) -> set[int]:
# Get merge-base with origin/main to check all PR commits
result = subprocess.run(
["git", "fetch", "origin", "main"],
["git", "fetch", "origin", "master"],
capture_output=True,
text=True,
timeout=600,
@@ -256,15 +256,15 @@ def get_added_lines(filename: str) -> set[int]:
)
result = subprocess.run(
["git", "merge-base", "HEAD", "origin/main"],
["git", "merge-base", "HEAD", "origin/master"],
capture_output=True,
text=True,
timeout=5,
)
if result.returncode != 0:
raise RuntimeError(
f"Failed to find merge-base with origin/main. "
f"Make sure origin/main exists (run 'git fetch origin main'). "
f"Failed to find merge-base with origin/master. "
f"Make sure origin/master exists (run 'git fetch origin master'). "
f"Error: {result.stderr.strip()}"
)