forked from pydot/pydot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Exceptions: Move to separate module, New hierarchy
- Module structure following example from NetworkX and other projects. This adds an `import pydot` to `core.py`, which is cyclic/circular, but necessary to make the exceptions available. Cyclic imports are not uncommon and Python can handle this. Using the exceptions in pydot source code now requires prefixing `pydot.`, for example: raise pydot.Error("Message") - Exception hierarchy changes. See ChangeLog and class docstrings in this commit for details. Additional background notes: - Removal of the unused exception class `InvocationException`: It was introduced in 842173c of 2008 (v1.0.2), but got in disuse when commits 9b3c1a1 and bc639e7 of 2016 (v1.2.0) fell back to using `Exception` and `assert` (`AssertionError`) again. If we ever need a custom class like this again in the future, it would probably have a different signature for context data (e.g. a DOT string, input and output), different parent class (or classes, e.g. `PydotException, CalledProcessError`) and perhaps a different name (e.g. ending in `...Error`), so no need to keep the old class around for that. Further additions to the exception hierarchy are likely before the final release of pydot 2.0. Discussed in pydot#171, pydot#230 and pydot#271.
- Loading branch information
1 parent
f250d65
commit 90936e7
Showing
4 changed files
with
36 additions
and
23 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,5 @@ | |
__version__ = "2.0.0.dev0" | ||
__license__ = "MIT" | ||
|
||
from pydot.exceptions import * | ||
from pydot.core import * |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
"""Exception classes for pydot.""" | ||
|
||
|
||
class PydotException(Exception): | ||
"""Base class for exceptions in Pydot. | ||
This base class will not be raised directly. | ||
Catch this base class to catch all derived exceptions, though be | ||
aware that pydot may raise Python built-in exceptions or pyparsing | ||
exceptions as well. | ||
""" | ||
|
||
|
||
class Error(PydotException): | ||
"""General error handling class.""" | ||
|
||
def __init__(self, value): | ||
self.value = value | ||
|
||
def __str__(self): | ||
return self.value |