Skip to content

Commit

Permalink
Leverage PEP 562 for backwards compatibility.
Browse files Browse the repository at this point in the history
As suggested #108 (comment)
  • Loading branch information
jrfonseca committed Sep 15, 2022
1 parent 9cc03fe commit 9dbec2c
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion xdot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,29 @@

import sys
assert sys.version_info.major >= 3
del sys

import importlib
import warnings


__all__ = ['dot', 'ui']


__author__ = "Jose Fonseca et al"


# Leverage PEP 562 to maintain backwards compatibility while still
# allowing xdot.dot to be used headlessly.
if sys.version_info >= (3, 7):
def __getattr__(name):
if name in ('dot', 'ui'):
return importlib.import_module("." + name, __name__)
if name in ('DotWidget', 'DotWindow'):
warnings.warn(f"w xdot.{name} is deprecated, use xdot.ui.{name} instead", UserWarning, stacklevel=2)
from . import ui
return getattr(ui, name)
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
else:
from . import dot
from . import ui
from .ui import DotWidget, DotWindow

0 comments on commit 9dbec2c

Please sign in to comment.