Skip to content

Commit

Permalink
Add stacklevel to warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
timj committed Jul 28, 2023
1 parent 7404561 commit 9d6355f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 7 additions & 1 deletion python/lsst/pipe/base/_datasetQueryConstraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
from collections.abc import Iterable, Iterator
from typing import Protocol

from lsst.utils.introspection import find_outside_stacklevel


class DatasetQueryConstraintVariant(Iterable, Protocol):
"""Base for all the valid variants for controlling
Expand Down Expand Up @@ -83,7 +85,11 @@ def fromExpression(cls, expression: str) -> "DatasetQueryConstraintVariant":
return cls.OFF
else:
if " " in expression:
warnings.warn("Whitespace found in expression will be trimmed", RuntimeWarning)
warnings.warn(

Check warning on line 88 in python/lsst/pipe/base/_datasetQueryConstraints.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/pipe/base/_datasetQueryConstraints.py#L88

Added line #L88 was not covered by tests
"Whitespace found in expression will be trimmed",
RuntimeWarning,
stacklevel=find_outside_stacklevel("lsst.pipe.base"),
)
expression = expression.replace(" ", "")
members = expression.split(",")
return cls.LIST(members)
Expand Down
4 changes: 3 additions & 1 deletion python/lsst/pipe/base/pipelineIR.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@

import yaml
from lsst.resources import ResourcePath, ResourcePathExpression
from lsst.utils.introspection import find_outside_stacklevel


class _Tags(enum.Enum):
Expand Down Expand Up @@ -315,7 +316,8 @@ def formatted(self, parameters: ParametersIR) -> ConfigIR:
warnings.warn(
f"config {key} contains value {match.group(0)} which is formatted like a "
"Pipeline parameter but was not found within the Pipeline, if this was not "
"intentional, check for a typo"
"intentional, check for a typo",
stacklevel=find_outside_stacklevel("lsst.pipe.base"),
)
return new_config

Expand Down

0 comments on commit 9d6355f

Please sign in to comment.