__init__.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. from __future__ import absolute_import
  2. # Copyright (c) 2010-2019 openpyxl
  3. from .strings import (
  4. basestring,
  5. unicode,
  6. bytes,
  7. file,
  8. tempfile,
  9. safe_string,
  10. safe_repr,
  11. )
  12. from .numbers import long, NUMERIC_TYPES
  13. try:
  14. from itertools import accumulate
  15. except ImportError:
  16. from .accumulate import accumulate
  17. import warnings
  18. from functools import wraps
  19. import inspect
  20. class DummyCode:
  21. pass
  22. # from https://github.com/tantale/deprecated/blob/master/deprecated/__init__.py
  23. # with an enhancement to update docstrings of deprecated functions
  24. string_types = (type(b''), type(u''))
  25. def deprecated(reason):
  26. if isinstance(reason, string_types):
  27. def decorator(func1):
  28. if inspect.isclass(func1):
  29. fmt1 = "Call to deprecated class {name} ({reason})."
  30. else:
  31. fmt1 = "Call to deprecated function {name} ({reason})."
  32. @wraps(func1)
  33. def new_func1(*args, **kwargs):
  34. #warnings.simplefilter('default', DeprecationWarning)
  35. warnings.warn(
  36. fmt1.format(name=func1.__name__, reason=reason),
  37. category=DeprecationWarning,
  38. stacklevel=2
  39. )
  40. return func1(*args, **kwargs)
  41. # Enhance docstring with a deprecation note
  42. deprecationNote = "\n\n.. note::\n Deprecated: " + reason
  43. if new_func1.__doc__:
  44. new_func1.__doc__ += deprecationNote
  45. else:
  46. new_func1.__doc__ = deprecationNote
  47. return new_func1
  48. return decorator
  49. elif inspect.isclass(reason) or inspect.isfunction(reason):
  50. raise TypeError("Reason for deprecation must be supplied")
  51. else:
  52. raise TypeError(repr(type(reason)))