Skip to content

fix: add missing stacklevel=2 to warnings.warn() calls in losses/ #8929

@rtmalikian

Description

@rtmalikian

Problem

28 calls to warnings.warn() in monai/losses/ are missing the stacklevel parameter. Without stacklevel=2, warnings point to the MONAI internal code instead of the user's calling code, making it difficult for users to identify which part of their script triggered the warning.

Proposed Fix

Add stacklevel=2 to all 28 warnings.warn() calls in:

  • monai/losses/dice.py (7 instances)
  • monai/losses/tversky.py (3 instances)
  • monai/losses/mcc_loss.py (3 instances)
  • monai/losses/focal_loss.py (3 instances)
  • monai/losses/hausdorff_loss.py (3 instances)
  • monai/losses/unified_focal_loss.py (3 instances)
  • monai/losses/spatial_mask.py (3 instances)
  • monai/losses/perceptual.py (2 instances)
  • monai/losses/adversarial_loss.py (1 instance)

Affected Files

  • monai/losses/dice.py
  • monai/losses/tversky.py
  • monai/losses/mcc_loss.py
  • monai/losses/focal_loss.py
  • monai/losses/hausdorff_loss.py
  • monai/losses/unified_focal_loss.py
  • monai/losses/spatial_mask.py
  • monai/losses/perceptual.py
  • monai/losses/adversarial_loss.py

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions