Skip to content

Commit

Permalink
Add warnings module
Browse files Browse the repository at this point in the history
  • Loading branch information
wmayner committed Jan 11, 2023
1 parent 412d978 commit 0430420
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions pyphi/warnings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# warnings.py

"""PyPhi warnings."""

import warnings


class PyPhiWarning(UserWarning):
"""Class for PyPhi warnings."""


def warn_about_tie_serialization(
name, serialize=False, deserialize=False, stacklevel=3
):
# XOR; exactly one of serialize or deserialize must be True
if not serialize ^ deserialize:
raise ValueError("Exactly one of ``serialize``, ``deserialize`` must be True")
if serialize:
msg = (
"Serializing ties to JSON in {name} is not currently "
"supported; tie information will be lost."
)
if deserialize:
msg = (
"Deserializing ties in {name} from JSON is not currently "
"supported; tie information was lost during serialization."
)
warnings.warn(msg.format(name=name), UserWarning, stacklevel=stacklevel)

0 comments on commit 0430420

Please sign in to comment.