fix: correct __all__ names in classification/loss modules - #123
Open
shivamlalakiya wants to merge 1 commit into
Open
shivamlalakiya wants to merge 1 commit into
shivamlalakiya wants to merge 1 commit into
Conversation
conftr.py, confts.py and scpo.py declare __all__ = ["ConfTr"], ["ConfTS"] and ["SCPO"], but the classes defined in those files are ConfTrLoss, ConfTSLoss and SCPOLoss. A wildcard import from any of the three modules raises AttributeError instead of binding the class: >>> from torchcp.classification.loss.conftr import * AttributeError: module 'torchcp.classification.loss.conftr' has no attribute 'ConfTr' Named imports (from torchcp.classification.loss import ConfTrLoss) are unaffected since the package __init__ imports the real names. This updates __all__ in each file to the actual class name.
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.
What
conftr.py,confts.pyandscpo.pyeach declare an__all__that names aclass that does not exist in the module:
A wildcard import from any of the three modules directly raises
AttributeErrorinstead of binding the class. Reproduced against the1.2.1 wheel from PyPI:
The named-import path is unaffected, because
torchcp/classification/loss/__init__.pyimports the real class names directly rather than going through
__all__:So this only bites a caller who does
from torchcp.classification.loss.conftr import *(or the
confts/scpoequivalents) instead of importing from the package.Fix
One line changed per file:
__all__now names the class that is actuallydefined (
ConfTrLoss,ConfTSLoss,SCPOLoss). Verified the wildcard importresolves correctly against the patched files:
This is a pure one-liner per file, no other behaviour changes.