From 39e0586192bc2c514f9a29363d7085848e0f794d Mon Sep 17 00:00:00 2001 From: ines Date: Wed, 1 Nov 2017 16:32:36 +0100 Subject: [PATCH] Add deprecated helper Uses warning to show DeprecationWarning and custom stack trace --- spacy/util.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/spacy/util.py b/spacy/util.py index 3fbd22aaf..460954b8f 100644 --- a/spacy/util.py +++ b/spacy/util.py @@ -11,6 +11,8 @@ import sys import textwrap import random from collections import OrderedDict +import inspect +import warnings from thinc.neural._classes.model import Model import functools @@ -501,6 +503,18 @@ def from_disk(path, readers, exclude): return path +def deprecated(message, filter='always'): + """Show a deprecation warning. + + message (unicode): The message to display. + filter (unicode): Filter value. + """ + stack = inspect.stack()[-1] + with warnings.catch_warnings(): + warnings.simplefilter(filter, DeprecationWarning) + warnings.warn_explicit(message, DeprecationWarning, stack[1], stack[2]) + + def print_table(data, title=None): """Print data in table format.