Update deprecated methods and add warnings

This commit is contained in:
ines 2017-11-01 16:49:42 +01:00
parent 260cb37224
commit 9659391944
7 changed files with 25 additions and 57 deletions

View File

@ -8,8 +8,14 @@ from . import util
def load(name, **overrides):
from .deprecated import resolve_load_name
name = resolve_load_name(name, **overrides)
depr_path = overrides.get('path')
if depr_path not in (True, False, None):
util.deprecated(
"As of spaCy v2.0, the keyword argument `path=` is deprecated. "
"You can now call spacy.load with the path as its first argument, "
"and the model's meta.json will be used to determine the language "
"to load. For example:\nnlp = spacy.load('{}')".format(depr_path),
'error')
return util.load_model(name, **overrides)

View File

@ -1,40 +1,4 @@
# coding: utf8
from __future__ import unicode_literals
from .util import prints
from .cli import download
from . import about
PRON_LEMMA = "-PRON-"
def depr_model_download(lang):
"""Replace en/de download modules within, warn and ownload default models.
lang (unicode): Language shortcut, 'en' or 'de'.
"""
prints("The spacy.%s.download command is now deprecated. Please use "
"spacy download [model name or shortcut] instead. For "
"more info, see the documentation:" % lang,
about.__docs_models__,
"Downloading default '%s' model now..." % lang,
title="Warning: deprecated command")
download(lang)
def resolve_load_name(name, **overrides):
"""Resolve model loading if deprecated path kwarg in overrides.
name (unicode): Name of model to load.
**overrides: Overrides specified in spacy.load().
RETURNS: Model name or value of path kwarg.
"""
if overrides.get('path') not in (None, False, True):
name = overrides.get('path')
prints("To load a model from a path, you can now use the first "
"argument. The model meta is used to load the Language class.",
"OLD: spacy.load('en', path='/some/path')",
"NEW: spacy.load('/some/path')",
title="Warning: deprecated argument 'path'")
return name

View File

@ -1,8 +0,0 @@
# coding: utf8
from __future__ import unicode_literals
from ..deprecated import depr_model_download
if __name__ == '__main__':
depr_model_download('de')

View File

@ -1,8 +0,0 @@
# coding: utf8
from __future__ import unicode_literals
from ..deprecated import depr_model_download
if __name__ == '__main__':
depr_model_download('en')

View File

@ -62,7 +62,11 @@ cdef class Tokenizer:
return (self.__class__, args, None, None)
cpdef Doc tokens_from_list(self, list strings):
# TODO: deprecation warning
util.deprecated(
"Tokenizer.from_from list is now deprecated. Create a new Doc "
"object instead and pass in the strings as the `words` keyword "
"argument, for example:\nfrom spacy.tokens import Doc\n"
"doc = Doc(nlp.vocab, words=[...])")
return Doc(self.vocab, words=strings)
@cython.boundscheck(False)

View File

@ -842,7 +842,10 @@ cdef class Doc:
"""
cdef unicode tag, lemma, ent_type
if len(args) == 3:
# TODO: Warn deprecation
util.deprecated(
"Positional arguments to Doc.merge are deprecated. Instead, "
"use the keyword arguments, for example tag=, lemma= or "
"ent_type=.")
tag, lemma, ent_type = args
attributes[TAG] = tag
attributes[LEMMA] = lemma

View File

@ -19,6 +19,7 @@ from ..attrs cimport IS_OOV, IS_TITLE, IS_UPPER, LIKE_URL, LIKE_NUM, LIKE_EMAIL
from ..attrs cimport IS_STOP, ID, ORTH, NORM, LOWER, SHAPE, PREFIX, SUFFIX
from ..attrs cimport LENGTH, CLUSTER, LEMMA, POS, TAG, DEP
from ..compat import is_config
from .. import util
from .. import about
from .underscore import Underscore
@ -330,8 +331,14 @@ cdef class Token:
return self.c.r_kids
property sent_start:
# TODO deprecation warning
def __get__(self):
util.deprecated(
"Token.sent_start is now deprecated. Use Token.is_sent_start "
"instead, which returns a boolean value or None if the answer "
"is unknown instead of a misleading 0 for False and 1 for "
"True. It also fixes a quirk in the old logic that would "
"always set the property to 0 for the first word of the "
"document.")
# Handle broken backwards compatibility case: doc[0].sent_start
# was False.
if self.i == 0: