Skip to content

Commit 1a8debf

Browse files
authored
Explicitly chain exceptions (#10242)
1 parent d01e85c commit 1a8debf

File tree

27 files changed

+61
-53
lines changed

27 files changed

+61
-53
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
4949

5050
### Changed
5151

52+
- Chained exceptions explicitly instead of implicitly ([#10242](https://github.com/pyg-team/pytorch_geometric/pull/10242))
5253
- Updated cuGraph examples to use buffered sampling which keeps data in memory and is significantly faster than the deprecated buffered sampling ([#10079](https://github.com/pyg-team/pytorch_geometric/pull/10079))
5354
- Updated Dockerfile to use latest from NVIDIA ([#9794](https://github.com/pyg-team/pytorch_geometric/pull/9794))
5455
- Dropped Python 3.8 support ([#9696](https://github.com/pyg-team/pytorch_geometric/pull/9606))

benchmark/inference/inference_benchmark.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,9 @@ def run(args: argparse.ArgumentParser):
5151
if args.device == 'xpu':
5252
try:
5353
import intel_extension_for_pytorch as ipex
54-
except ImportError:
55-
raise RuntimeError('XPU device requires IPEX to be installed')
54+
except ImportError as e:
55+
raise RuntimeError(
56+
'XPU device requires IPEX to be installed') from e
5657

5758
if ((args.device == 'cuda' and not torch.cuda.is_available())
5859
or (args.device == 'xpu' and not torch.xpu.is_available())):

benchmark/multi_gpu/training/training_benchmark_cuda.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def run_cuda(rank: int, world_size: int, args: argparse.ArgumentParser,
2727
argparser = get_predefined_args()
2828
argparser.add_argument('--n-gpus', default=1, type=int)
2929
args = argparser.parse_args()
30-
setattr(args, 'device', 'cuda')
30+
args.device = 'cuda'
3131

3232
assert args.dataset in supported_sets.keys(), \
3333
f"Dataset {args.dataset} isn't supported."

benchmark/multi_gpu/training/training_benchmark_xpu.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def custom_optimizer(model: Any, optimizer: Any) -> Tuple[Any, Any]:
4444

4545
argparser = get_predefined_args()
4646
args = argparser.parse_args()
47-
setattr(args, 'device', 'xpu')
47+
args.device = 'xpu'
4848

4949
assert args.dataset in supported_sets.keys(), \
5050
f"Dataset {args.dataset} isn't supported."

benchmark/training/training_benchmark.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,9 @@ def run(args: argparse.ArgumentParser):
104104
if args.device == 'xpu':
105105
try:
106106
import intel_extension_for_pytorch as ipex
107-
except ImportError:
108-
raise RuntimeError('XPU device requires IPEX to be installed')
107+
except ImportError as e:
108+
raise RuntimeError(
109+
'XPU device requires IPEX to be installed') from e
109110

110111
if not device_conditions[args.device]():
111112
raise RuntimeError(f'{args.device.upper()} is not available')

examples/llm/g_retriever_utils/rag_backend_utils.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,13 @@ class to use. Defaults to LocalFeatureStore.
174174
"""
175175
# Will return attribute errors for missing attributes
176176
if not issubclass(graph_db, ConvertableGraphStore):
177-
getattr(graph_db, "from_data")
178-
getattr(graph_db, "from_hetero_data")
179-
getattr(graph_db, "from_partition")
177+
graph_db.from_data # noqa: B018
178+
graph_db.from_hetero_data # noqa: B018
179+
graph_db.from_partition # noqa: B018
180180
elif not issubclass(feature_db, ConvertableFeatureStore):
181-
getattr(feature_db, "from_data")
182-
getattr(feature_db, "from_hetero_data")
183-
getattr(feature_db, "from_partition")
181+
feature_db.from_data # noqa: B018
182+
feature_db.from_hetero_data # noqa: B018
183+
feature_db.from_partition # noqa: B018
184184

185185
# Resolve callable methods
186186
node_method_kwargs = node_method_kwargs \

examples/multi_gpu/ogbn_train_cugraph.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ def arg_parse():
6565
parser.add_argument('-e', '--epochs', type=int, default=50)
6666
parser.add_argument('-b', '--batch_size', type=int, default=1024)
6767
parser.add_argument('--fan_out', type=int, default=10)
68-
parser.add_argument('--eval_steps', type=int, default=1000)
6968
parser.add_argument('--warmup_steps', type=int, default=20)
7069
parser.add_argument('--dropout', type=float, default=0.5)
7170
parser.add_argument(
@@ -227,7 +226,6 @@ def run_train(rank, args, data, world_size, cugraph_id, model, split_idx,
227226

228227
dist.barrier()
229228

230-
args.eval_steps
231229
warmup_steps = args.warmup_steps
232230
dist.barrier()
233231
torch.cuda.synchronize()

graphgym/configs_gen.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ def gen_grid(args, config, config_budget={}):
152152
}
153153
else:
154154
raise ValueError('Only 2-level config files are supported')
155-
var_repr = str(var).strip("[]").strip("''")
155+
var_repr = str(var).strip("[]").strip("''") # noqa: B005
156156
fname_out += f'-{vars_alias[id]}={var_repr}'
157157
if len(config_budget) > 0:
158158
config_out = match_baseline_cfg(config_out, config_budget)
@@ -221,7 +221,7 @@ def gen_grid_sample(args, config, config_budget={}, compare_alias_list=[]):
221221
else:
222222
raise ValueError(
223223
'Only 2-level config files are supported')
224-
var_repr = str(var).strip("[]").strip("''")
224+
var_repr = str(var).strip("[]").strip("''") # noqa: B005
225225
fname_out += f'-{vars_alias[id]}={var_repr}'
226226
if len(config_budget) > 0:
227227
config_out = match_baseline_cfg(config_out, config_budget,

pyproject.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,18 @@ target-version = "py39"
157157

158158
[tool.ruff.lint]
159159
select = [
160+
"B", # flake8-bugbear
160161
"D", # pydocstyle
161162
]
162163
ignore = [
164+
"B006", # TODO Don't ignore "Do not use mutable data structures for argument defaults"
165+
"B007", # TODO Don't ignore "Loop control variable `{name}` not used within loop body"
166+
"B008", # TODO Don't ignore "Do not perform function call `{name}` in argument defaults; instead, perform the call within the function, or read the default from a module-level singleton variable"
167+
"B020", # TODO Don't ignore "Loop control variable `{name}` overrides iterable it iterates"
168+
"B024", # TODO Don't ignore "`{name}` is an abstract base class, but it has no abstract methods or properties"
169+
"B026", # TODO Don't ignore "Star-arg unpacking after a keyword argument is strongly discouraged"
170+
"B027", # TODO Don't ignore "`{name}` is an empty method in an abstract base class, but has no abstract decorator"
171+
"B028", # TODO Don't ignore "No explicit `stacklevel` keyword argument found"
163172
"D100", # TODO Don't ignore "Missing docstring in public module"
164173
"D101", # TODO Don't ignore "Missing docstring in public class"
165174
"D102", # TODO Don't ignore "Missing docstring in public method"

test/data/test_dataset.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def test_in_memory_dataset():
6464
assert dataset[1].test_str == '2'
6565

6666
with pytest.warns(UserWarning, match="internal storage format"):
67-
dataset.data
67+
dataset.data # noqa: B018
6868

6969
assert torch.equal(dataset.x, torch.cat([x1, x2], dim=0))
7070
assert dataset.edge_index.tolist() == [

0 commit comments

Comments
 (0)