From 54fe8719355534ec1dd51b20252bf154c25a8be3 Mon Sep 17 00:00:00 2001 From: Adriane Boyd Date: Sun, 27 Sep 2020 14:37:28 +0200 Subject: [PATCH] Fix formatting, refactor pickle5 exceptions --- spacy/lang/zh/__init__.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/spacy/lang/zh/__init__.py b/spacy/lang/zh/__init__.py index d222e78f2..f9887a4df 100644 --- a/spacy/lang/zh/__init__.py +++ b/spacy/lang/zh/__init__.py @@ -1,4 +1,4 @@ -from typing import Optional, List, Dict, Any +from typing import Optional, List from enum import Enum import tempfile import srsly @@ -16,7 +16,7 @@ from ... import util _PKUSEG_INSTALL_MSG = "install pkuseg and pickle5 with `pip install pkuseg==0.0.25 pickle5`" -_PKUSEG_PICKLE_WARNING = "Failed to force pkuseg model to use pickle protocol 4. If you're saving this model with python 3.8, it may not work with python 3.6-3.7. +_PKUSEG_PICKLE_WARNING = "Failed to force pkuseg model to use pickle protocol 4. If you're saving this model with python 3.8, it may not work with python 3.6-3.7." DEFAULT_CONFIG = """ [nlp] @@ -158,7 +158,9 @@ class ChineseTokenizer(DummyTokenizer): features = pickle5.load(fileh) with open(tempdir / "features.pkl", "wb") as fileh: pickle5.dump(features, fileh, protocol=4) - except: + except ImportError as e: + raise(e) + except Exception: warnings.warn(_PKUSEG_PICKLE_WARNING) with open(tempdir / "features.pkl", "rb") as fileh: pkuseg_features_b = fileh.read() @@ -238,7 +240,9 @@ class ChineseTokenizer(DummyTokenizer): features = pickle5.load(fileh) with open(path / "features.pkl", "wb") as fileh: pickle5.dump(features, fileh, protocol=4) - except: + except ImportError as e: + raise(e) + except Exception: warnings.warn(_PKUSEG_PICKLE_WARNING) def save_pkuseg_processors(path):