Use {} for better performance in dict()#8751
Conversation
Signed-off-by: Benedikt Johannes <benedikt.johannes.hofer@gmail.com>
📝 WalkthroughWalkthroughChanged initialization of Estimated code review effort🎯 1 (Trivial) | ⏱️ ~2 minutes 🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
monai/apps/auto3dseg/auto_runner.py (1)
232-239:{}is correct; the initialisation is redundant.Every branch in lines 233–239 either overwrites
self.data_src_cfgor raises, so the{}on line 232 is never read. You can remove the initialisation entirely and let the branches assign directly — or, if you prefer an explicit fallback, restructure withelse: raise.♻️ Proposed cleanup
- self.data_src_cfg = {} if isinstance(input, dict): self.data_src_cfg = input elif isinstance(input, str) and os.path.isfile(input): self.data_src_cfg = ConfigParser.load_config_file(input) logger.info(f"Loading input config {input}") else: raise ValueError(f"{input} is not a valid file or dict")🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@monai/apps/auto3dseg/auto_runner.py` around lines 232 - 239, The initial assignment self.data_src_cfg = {} is redundant because every branch in the if/elif/else either assigns self.data_src_cfg or raises; remove that initialisation and have the branches assign directly (keep the checks on input, the call to ConfigParser.load_config_file, the logger.info call, and the ValueError in the else branch) so only the relevant branch sets self.data_src_cfg.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@monai/apps/auto3dseg/auto_runner.py`:
- Around line 232-239: The initial assignment self.data_src_cfg = {} is
redundant because every branch in the if/elif/else either assigns
self.data_src_cfg or raises; remove that initialisation and have the branches
assign directly (keep the checks on input, the call to
ConfigParser.load_config_file, the logger.info call, and the ValueError in the
else branch) so only the relevant branch sets self.data_src_cfg.
|
Hi @benediktjohannes I not sure this change is really necessary. I know I merged the previous PR about replacing |
We replaced this in #1423 e.g. in line "properties = dict()" to "properties = {}" as well, so I think it's better. |
|
cc @ericspod |
|
I can merge this now but the thing with these minor changes is that they would only matter in high frequency code anyway. The lookup time saved only matters if the line is executed a very large number of times. |
|
@ericspod thanks! Could you please also merge the one in the hot loop path? This should be way more important. Thanks! |
Description
Follow-up for #8748 and so on (I'll combine these changes in future 👍)
Types of changes
./runtests.sh -f -u --net --coverage../runtests.sh --quick --unittests --disttests.make htmlcommand in thedocs/folder.