已合并
[sync] PR-35516: Fix pyrefly\set_linter\stabel_shim_version_linter error #35534
ascend-robot创建于 5月13日
[sync] PR-35516: Fix pyrefly\set_linter\stabel_shim_version_linter error #35534
已合并
共 3 个文件变更+60-50
| @@ -3,7 +3,9 @@ | |||
| 3 | python-version = "3.12" | 3 | python-version = "3.12" |
| 4 | 4 | ||
| 5 | project-includes = [ | 5 | project-includes = [ |
| 6 | - "torch", | 6 | + "torch_npu", |
| 7 | + "torchnpugen", | ||
| 8 | + "test", | ||
| 7 | "caffe2", | 9 | "caffe2", |
| 8 | "test/test_bundled_images.py", | 10 | "test/test_bundled_images.py", |
| 9 | "test/test_bundled_inputs.py", | 11 | "test/test_bundled_inputs.py", |
| @@ -21,45 +23,45 @@ project-includes = [ | |||
| 21 | ] | 23 | ] |
| 22 | project-excludes = [ | 24 | project-excludes = [ |
| 23 | "tools/**", | 25 | "tools/**", |
| 24 | - "torch/_inductor/runtime/triton_heuristics.py", | 26 | + "torch_npu/_inductor/runtime/triton_heuristics.py", |
| 25 | - "torch/_inductor/runtime/triton_helpers.py", | 27 | + "torch_npu/_inductor/runtime/triton_helpers.py", |
| 26 | - "torch/_inductor/runtime/halide_helpers.py", | 28 | + "torch_npu/_inductor/runtime/halide_helpers.py", |
| 27 | - "torch/utils/data/typing.ipynb", | 29 | + "torch_npu/utils/data/typing.ipynb", |
| 28 | - "torch/utils/data/dataframes_pipes.ipynb", | 30 | + "torch_npu/utils/data/dataframes_pipes.ipynb", |
| 29 | - "torch/utils/data/standard_pipes.ipynb", | 31 | + "torch_npu/utils/data/standard_pipes.ipynb", |
| 30 | - "torch/onnx/_internal/exporter/_torchlib/ops/nn.py", | 32 | + "torch_npu/onnx/_internal/exporter/_torchlib/ops/nn.py", |
| 31 | - "torch/include/**", | 33 | + "torch_npu/include/**", |
| 32 | - "torch/csrc/**", | 34 | + "torch_npu/csrc/**", |
| 33 | - "torch/distributed/elastic/agent/server/api.py", | 35 | + "torch_npu/distributed/elastic/agent/server/api.py", |
| 34 | - "torch/testing/_internal/**", | 36 | + "torch_npu/testing/_internal/**", |
| 35 | - "torch/distributed/fsdp/fully_sharded_data_parallel.py", | 37 | + "torch_npu/distributed/fsdp/fully_sharded_data_parallel.py", |
| 36 | - "torch/ao/quantization/pt2e/_affine_quantization.py", | 38 | + "torch_npu/ao/quantization/pt2e/_affine_quantization.py", |
| 37 | - "torch/nn/modules/pooling.py", | 39 | + "torch_npu/nn/modules/pooling.py", |
| 38 | - "torch/nn/parallel/_functions.py", | 40 | + "torch_npu/nn/parallel/_functions.py", |
| 39 | - "torch/_appdirs.py", | 41 | + "torch_npu/_appdirs.py", |
| 40 | - "torch/multiprocessing/pool.py", | 42 | + "torch_npu/multiprocessing/pool.py", |
| 41 | - "torch/overrides.py", | 43 | + "torch_npu/overrides.py", |
| 42 | "*/__pycache__/**", | 44 | "*/__pycache__/**", |
| 43 | "*/.*", | 45 | "*/.*", |
| 44 | - "torch/_inductor/kernel/vendored_templates/cutedsl/kernels/**", | 46 | + "torch_npu/_inductor/kernel/vendored_templates/cutedsl/kernels/**", |
| 45 | - "torch/_inductor/kernel/vendored_templates/cutedsl/dense_blockscaled_gemm_persistent.py", | 47 | + "torch_npu/_inductor/kernel/vendored_templates/cutedsl/dense_blockscaled_gemm_persistent.py", |
| 46 | ] | 48 | ] |
| 47 | ignore-missing-imports = [ | 49 | ignore-missing-imports = [ |
| 48 | # XPU memory symbols not present for builds without XPU support | 50 | # XPU memory symbols not present for builds without XPU support |
| 49 | - "torch._C._xpu_beginAllocateCurrentThreadToPool", | 51 | + "torch_npu._C._xpu_beginAllocateCurrentThreadToPool", |
| 50 | - "torch._C._xpu_endAllocateToPool", | 52 | + "torch_npu._C._xpu_endAllocateToPool", |
| 51 | - "torch._C._xpu_releasePool", | 53 | + "torch_npu._C._xpu_releasePool", |
| 52 | - "torch._C._xpu_XPUAllocator", | 54 | + "torch_npu._C._xpu_XPUAllocator", |
| 53 | - "torch._C._XPUMemPool", | 55 | + "torch_npu._C._XPUMemPool", |
| 54 | - "torch._C._StaticXpuLauncher", | 56 | + "torch_npu._C._StaticXpuLauncher", |
| 55 | - "torch._C._jit_tree_views.*", | 57 | + "torch_npu._C._jit_tree_views.*", |
| 56 | - "torch.for_onnx.onnx.*", | 58 | + "torch_npu.for_onnx.onnx.*", |
| 57 | - "torch.ao.quantization.experimental.apot_utils.*", | 59 | + "torch_npu.ao.quantization.experimental.apot_utils.*", |
| 58 | - "torch.ao.quantization.experimental.quantizer.*", | 60 | + "torch_npu.ao.quantization.experimental.quantizer.*", |
| 59 | - "torch.ao.quantization.experimental.observer.*", | 61 | + "torch_npu.ao.quantization.experimental.observer.*", |
| 60 | - "torch.ao.quantization.experimental.APoT_tensor.*", | 62 | + "torch_npu.ao.quantization.experimental.APoT_tensor.*", |
| 61 | - "torch.ao.quantization.experimental.fake_quantize_function.*", | 63 | + "torch_npu.ao.quantization.experimental.fake_quantize_function.*", |
| 62 | - "torch.ao.quantization.experimental.fake_quantize.*", | 64 | + "torch_npu.ao.quantization.experimental.fake_quantize.*", |
| 63 | "triton.*", | 65 | "triton.*", |
| 64 | "tensorflow.*", | 66 | "tensorflow.*", |
| 65 | "tensorboard.*", | 67 | "tensorboard.*", |
| @@ -103,8 +105,8 @@ ignore-missing-imports = [ | |||
| 103 | "deeplearning.*", | 105 | "deeplearning.*", |
| 104 | "einops.*", | 106 | "einops.*", |
| 105 | "libfb.*", | 107 | "libfb.*", |
| 106 | - "torch.fb.*", | 108 | + "torch_npu.fb.*", |
| 107 | - "torch.*.fb.*", | 109 | + "torch_npu.*.fb.*", |
| 108 | "torch_xla.*", | 110 | "torch_xla.*", |
| 109 | "onnx.*", | 111 | "onnx.*", |
| 110 | "onnxruntime.*", | 112 | "onnxruntime.*", |
| @@ -133,7 +135,7 @@ search-path = ["tools/experimental"] | |||
| 133 | 135 | ||
| 134 | # Dynamo sub-config - note, we experiment with stricter typing here | 136 | # Dynamo sub-config - note, we experiment with stricter typing here |
| 135 | [[sub-config]] | 137 | [[sub-config]] |
| 136 | -matches = "torch/_dynamo/**" | 138 | +matches = "torch_npu/_dynamo/**" |
| 137 | [sub-config.errors] | 139 | [sub-config.errors] |
| 138 | implicit-import = false | 140 | implicit-import = false |
| 139 | implicit-any = true | 141 | implicit-any = true |
| @@ -143,19 +145,19 @@ implicit-any = true | |||
| 143 | # unannotated-return=true | 145 | # unannotated-return=true |
| 144 | 146 | ||
| 145 | [[sub-config]] | 147 | [[sub-config]] |
| 146 | -matches = "torch/_dispatch/**" | 148 | +matches = "torch_npu/_dispatch/**" |
| 147 | [sub-config.errors] | 149 | [sub-config.errors] |
| 148 | implicit-import = false | 150 | implicit-import = false |
| 149 | implicit-any = true | 151 | implicit-any = true |
| 150 | 152 | ||
| 151 | [[sub-config]] | 153 | [[sub-config]] |
| 152 | -matches = "torch/_subclasses/**" | 154 | +matches = "torch_npu/_subclasses/**" |
| 153 | [sub-config.errors] | 155 | [sub-config.errors] |
| 154 | implicit-import = false | 156 | implicit-import = false |
| 155 | implicit-any = true | 157 | implicit-any = true |
| 156 | 158 | ||
| 157 | [[sub-config]] | 159 | [[sub-config]] |
| 158 | -matches = "torch/_functorch/**" | 160 | +matches = "torch_npu/_functorch/**" |
| 159 | [sub-config.errors] | 161 | [sub-config.errors] |
| 160 | implicit-import = false | 162 | implicit-import = false |
| 161 | implicit-any = true | 163 | implicit-any = true |
| @@ -12,12 +12,16 @@ BRACKETS = {"{": "}", "(": ")", "[": "]"} | |||
| 12 | BRACKETS_INV = {j: i for i, j in BRACKETS.items()} | 12 | BRACKETS_INV = {j: i for i, j in BRACKETS.items()} |
| 13 | 13 | ||
| 14 | 14 | ||
| 15 | +_FSTRING_SENTINEL = ("__fstring_start__",) | ||
| 16 | + | ||
| 17 | + | ||
| 15 | def bracket_pairs(tokens: Sequence[TokenInfo]) -> dict[int, int]: | 18 | def bracket_pairs(tokens: Sequence[TokenInfo]) -> dict[int, int]: |
| 16 | """Returns a dictionary mapping opening to closing brackets""" | 19 | """Returns a dictionary mapping opening to closing brackets""" |
| 17 | braces: dict[int, int] = {} | 20 | braces: dict[int, int] = {} |
| 18 | - stack: list[int] = [] | 21 | + stack: list[object] = [] |
| 19 | in_fstring = False | 22 | in_fstring = False |
| 20 | 23 | ||
| 24 | + t: TokenInfo | None = None | ||
| 21 | for i, t in enumerate(tokens): | 25 | for i, t in enumerate(tokens): |
| 22 | if t.type == token.OP and not in_fstring: | 26 | if t.type == token.OP and not in_fstring: |
| 23 | if t.string in BRACKETS: | 27 | if t.string in BRACKETS: |
| @@ -26,20 +30,24 @@ def bracket_pairs(tokens: Sequence[TokenInfo]) -> dict[int, int]: | |||
| 26 | if not stack: | 30 | if not stack: |
| 27 | raise ParseError(t, "Never opened") | 31 | raise ParseError(t, "Never opened") |
| 28 | begin = stack.pop() | 32 | begin = stack.pop() |
| 33 | + if not isinstance(begin, int) or not 0 <= begin < len(tokens): | ||
| 34 | + raise ParseError(t, f"Mismatched braces at {begin}") | ||
| 29 | 35 | ||
| 30 | - if not (stack and stack[-1] == FSTRING_START): | 36 | + if not (stack and stack[-1] is _FSTRING_SENTINEL): |
| 31 | braces[begin] = i | 37 | braces[begin] = i |
| 32 | 38 | ||
| 33 | b = tokens[begin].string | 39 | b = tokens[begin].string |
| 34 | if b != inv: | 40 | if b != inv: |
| 35 | raise ParseError(t, f"Mismatched braces '{b}' at {begin}") | 41 | raise ParseError(t, f"Mismatched braces '{b}' at {begin}") |
| 36 | elif t.type == FSTRING_START: | 42 | elif t.type == FSTRING_START: |
| 37 | - stack.append(FSTRING_START) | 43 | + stack.append(_FSTRING_SENTINEL) |
| 38 | in_fstring = True | 44 | in_fstring = True |
| 39 | elif t.type == FSTRING_END: | 45 | elif t.type == FSTRING_END: |
| 40 | - if stack.pop() != FSTRING_START: | 46 | + if not stack or stack.pop() is not _FSTRING_SENTINEL: |
| 41 | raise ParseError(t, "Mismatched FSTRING_START/FSTRING_END") | 47 | raise ParseError(t, "Mismatched FSTRING_START/FSTRING_END") |
| 42 | in_fstring = False | 48 | in_fstring = False |
| 43 | if stack: | 49 | if stack: |
| 44 | - raise ParseError(t, "Left open") | 50 | + raise ParseError( |
| 51 | + t if t is not None else tokens[-1], "Left open" | ||
| 52 | + ) | ||
| 45 | return braces | 53 | return braces |
| @@ -245,7 +245,7 @@ def get_added_lines(filename: str) -> set[int]: | |||
| 245 | 245 | ||
| 246 | # Get merge-base with origin/main to check all PR commits | 246 | # Get merge-base with origin/main to check all PR commits |
| 247 | result = subprocess.run( | 247 | result = subprocess.run( |
| 248 | - ["git", "fetch", "origin", "main"], | 248 | + ["git", "fetch", "origin", "master"], |
| 249 | capture_output=True, | 249 | capture_output=True, |
| 250 | text=True, | 250 | text=True, |
| 251 | timeout=600, | 251 | timeout=600, |
| @@ -256,15 +256,15 @@ def get_added_lines(filename: str) -> set[int]: | |||
| 256 | ) | 256 | ) |
| 257 | 257 | ||
| 258 | result = subprocess.run( | 258 | result = subprocess.run( |
| 259 | - ["git", "merge-base", "HEAD", "origin/main"], | 259 | + ["git", "merge-base", "HEAD", "origin/master"], |
| 260 | capture_output=True, | 260 | capture_output=True, |
| 261 | text=True, | 261 | text=True, |
| 262 | timeout=5, | 262 | timeout=5, |
| 263 | ) | 263 | ) |
| 264 | if result.returncode != 0: | 264 | if result.returncode != 0: |
| 265 | raise RuntimeError( | 265 | raise RuntimeError( |
| 266 | - f"Failed to find merge-base with origin/main. " | 266 | + f"Failed to find merge-base with origin/master. " |
| 267 | - f"Make sure origin/main exists (run 'git fetch origin main'). " | 267 | + f"Make sure origin/master exists (run 'git fetch origin master'). " |
| 268 | f"Error: {result.stderr.strip()}" | 268 | f"Error: {result.stderr.strip()}" |
| 269 | ) | 269 | ) |
| 270 | 270 | ||