fix: use raise instead of return for exceptions and avoid mutable default args#7915
Open
Mr-Neutr0n wants to merge 1 commit intodmlc:masterfrom
Open
fix: use raise instead of return for exceptions and avoid mutable default args#7915Mr-Neutr0n wants to merge 1 commit intodmlc:masterfrom
Mr-Neutr0n wants to merge 1 commit intodmlc:masterfrom
Conversation
…ault args - han/utils.py: change `return NotImplementedError` to `raise NotImplementedError` - evolveGCN/train.py: change `return NotImplementedError` to `raise NotImplementedError` - bgnn/BGNN.py: change `raise NotImplemented` to `raise NotImplementedError` - jtnn/jtnn_dec.py: replace mutable default `clique=[]` with `None` - jtnn/chemutils.py: replace mutable defaults `prev_nodes=[]`, `prev_amap=[]` with `None` `return NotImplementedError(...)` silently returns the exception object instead of raising it, so callers never see the error. `raise NotImplemented(...)` raises a `TypeError` with a confusing message because `NotImplemented` is a built-in constant, not an exception class. Mutable default arguments are shared across calls and can cause subtle bugs when mutated.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
examples/pytorch/han/utils.py(line 266): Changedreturn NotImplementedError(...)toraise NotImplementedError(...). The original code silently returns the exception object instead of raising it, so unsupported datasets never trigger an error.examples/pytorch/evolveGCN/train.py(line 44): Changedreturn NotImplementedError(...)toraise NotImplementedError(...). Same silent-return bug — unsupported models are never flagged.examples/pytorch/bgnn/BGNN.py(line 212): Changedraise NotImplemented(...)toraise NotImplementedError(...).NotImplementedis a built-in constant (used for rich comparisons), not an exception class, soraise NotImplemented(...)throws a confusingTypeErrorinstead of the intendedNotImplementedError.examples/pytorch/jtnn/jtnn/jtnn_dec.py(line 83): Replaced mutable default argumentclique=[]withclique=Noneand added aNoneguard. Mutable defaults are shared across all calls and can cause subtle bugs when mutated.examples/pytorch/jtnn/jtnn/chemutils.py(line 317): Replaced mutable default argumentsprev_nodes=[]andprev_amap=[]withNoneand addedNoneguards. Same mutable-default issue.Test plan