Skip to content

Conversation

SigureMo
Copy link
Member

@SigureMo SigureMo commented Jun 14, 2025

PR Category

User Experience

PR Types

Improvements

Description

准备引入 Ruff SIM1171,将连续多个 with 语句合并为一个,减少代码缩进层级,此为 part1

Tracker

Footnotes

  1. https://docs.astral.sh/ruff/rules/multiple-with-statements/

@SigureMo SigureMo requested review from zrr1999 and gouzil as code owners June 14, 2025 20:09
@SigureMo SigureMo requested review from Copilot and removed request for zrr1999 and gouzil June 14, 2025 20:13
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the code by combining multiple nested with statements into a single, multi-context manager block in order to reduce unnecessary indentation and improve readability. The changes span several test files and utility modules to streamline context management, enhancing overall code maintainability.

Reviewed Changes

Copilot reviewed 108 out of 108 changed files in this pull request and generated no comments.

Show a summary per file
File Description
test/deprecated/legacy_test/test_entry_attr2_deprecated.py Combined nested with statements into a single block to reduce indentation.
test/deprecated/legacy_test/test_dataset_dataloader_deprecated.py Unified multiple with statements for clearer context management.
test/deprecated/legacy_test/test_conv3d_layer_deprecated.py Reduced nesting by combining with statements for unique name guards and program guards.
test/deprecated/legacy_test/test_conv2d_transpose_layer_deprecated.py Simplified context management by merging with statements in both base_layer and functional methods.
test/deprecated/legacy_test/test_conv2d_layer_deprecated.py Combined nested with statements for improved readability in base_layer and functional methods.
test/deprecated/ir/inference/test_trt_matmul_quant_dequant_deprecated.py Refactored with statements to use multi-context blocks for program guards and unique name guards.
test/deprecated/ir/inference/test_trt_fc_fuse_quant_dequant_pass_deprecated.py Merged with statements to streamline guard usage for both main and test programs.
test/deprecated/ir/inference/test_trt_conv_quant_dequant_pass_deprecated.py Combined with statements to reduce nesting in the setup of program and unique name guards.
test/deprecated/auto_parallel/auto_parallel_pass_test_base_deprecated.py Unified with statements for program guard, scope guard, and unique name guard in a single block.
test/amp/test_amp_o2_embedding_model.py Merged with statements for unique name and program guards in the AMP model setup.
test/amp/test_amp_master_weight.py Combined with statements to simplify context management in the AMP master weight test.
test/amp/test_amp_list.py Refactored with statements to group IR guards and program guards, reducing nested block structure.
test/amp/test_amp_decorate.py Unified with statements for IR guard and program guard in the AMP decorate test.
test/amp/test_amp_api.py Combined with statements to streamline guard usage across different AMP API tests.
python/paddle/tensorrt/util.py Refactored with statements by grouping IR guard and program guard for better clarity.
python/paddle/nn/layer/rnn.py Merged with statements to combine program_guard and no_grad contexts, improving readability.
python/paddle/jit/dy2static/utils.py Combined nested with statements in composed_guard for a cleaner implementation.
python/paddle/distributed/fleet/recompute/recompute.py Combined nested with statements to handle AMP auto_cast and RNG state management more succinctly.
python/paddle/distributed/auto_parallel/static/tuner/rule_based_tuner.py Streamlined context management by merging with statements for program_guard and name generator switching.
python/paddle/cinn/compiler/compute_code_generator.py Consolidated with statements for variable table and loop context management, reducing unnecessary nesting.

@SigureMo
Copy link
Member Author

skip-reason: codestyle only

@SigureMo SigureMo changed the title [CodeStyle][SIM117] Combine multiple with statements (part1) [CodeStyle][SIM117] Combine multiple with statements (part1) Jun 15, 2025
@SigureMo SigureMo merged commit 7140efd into PaddlePaddle:develop Jun 15, 2025
66 of 73 checks passed
@SigureMo SigureMo deleted the ruff/sim117-part1 branch June 15, 2025 09:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants