Skip to content

Commit

Permalink
Expose warnings as pronto.warnings and improve warnings hierarchy
Browse files Browse the repository at this point in the history
  • Loading branch information
althonos committed Oct 10, 2019
1 parent 9a74e2a commit 7df2221
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

## 🚩 Table of Contents

- [Overview](#-overview)
- [Overview](#%EF%B8%8F-overview)
- [Supported Languages](#%EF%B8%8F-supported-languages)
- [Installing](#-installing)
- [Examples](#-examples)
Expand Down
4 changes: 4 additions & 0 deletions pronto/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
.strip()
)

from .utils import warnings
from .entity import Entity
from .definition import Definition
from .metadata import Metadata, Subset
Expand All @@ -18,6 +19,9 @@
from .xref import Xref

__all__ = [
# modules
warnings.__name__,
# classes
Ontology.__name__,
Entity.__name__,
Term.__name__,
Expand Down
4 changes: 3 additions & 1 deletion pronto/parsers/_fastobo.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,9 @@ def add(src, dst=None, cb=None):

def todo():
return lambda c: warnings.warn(
f"cannot process `{c}`", NotImplementedWarning, stacklevel=3
f"cannot process `{c}`",
NotImplementedWarning,
stacklevel=3
)

_callbacks = {
Expand Down
26 changes: 25 additions & 1 deletion pronto/utils/warnings.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,26 @@
class NotImplementedWarning(UserWarning):
"""Warnings raised by the library.
"""

import warnings

class ProntoWarning(Warning):
"""The class for all warnings raised by `pronto`.
"""
pass

class NotImplementedWarning(ProntoWarning, NotImplementedError):
"""Some part of the code is yet to be implemented.
"""
pass

class UnstableWarning(ProntoWarning):
"""The behaviour of the executed code might change in the future.
"""
pass

class SyntaxWarning(ProntoWarning, SyntaxError):
"""The parsed document contains incomplete or unsound constructs.
"""
def __init__(self, *args, **kwargs):
ProntoWarning.__init__(self, *args, **kwargs)
SyntaxError.__init__(self, *args, **kwargs)

0 comments on commit 7df2221

Please sign in to comment.