mirror of
https://github.com/explosion/spaCy.git
synced 2024-12-24 00:46:28 +03:00
Add SimpleFrozenDict util to use as default function argument
This commit is contained in:
parent
581d318971
commit
5768df4f09
|
@ -245,6 +245,8 @@ class Errors(object):
|
|||
"the meta.json. Vector names are required to avoid issue #1660.")
|
||||
E093 = ("token.ent_iob values make invalid sequence: I without B\n{seq}")
|
||||
E094 = ("Error reading line {line_num} in vectors file {loc}.")
|
||||
E095 = ("Can't write to frozen dictionary. This is likely an internal "
|
||||
"error. Are you writing to a default function argument?")
|
||||
|
||||
|
||||
@add_codes
|
||||
|
|
|
@ -606,3 +606,18 @@ def use_gpu(gpu_id):
|
|||
def fix_random_seed(seed=0):
|
||||
random.seed(seed)
|
||||
numpy.random.seed(seed)
|
||||
|
||||
|
||||
class SimpleFrozenDict(dict):
|
||||
"""Simplified implementation of a frozen dict, mainly used as default
|
||||
function or method argument (for arguments that should default to empty
|
||||
dictionary). Will raise an error if user or spaCy attempts to add to dict.
|
||||
"""
|
||||
def __setitem__(self, key, value):
|
||||
raise NotImplementedError(Errors.E095)
|
||||
|
||||
def pop(self, key, default=None):
|
||||
raise NotImplementedError(Errors.E095)
|
||||
|
||||
def update(self, other):
|
||||
raise NotImplementedError(Errors.E095)
|
||||
|
|
Loading…
Reference in New Issue
Block a user