diff --git a/CHANGELOG.md b/CHANGELOG.md index c8d1195e..387a272b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,7 +12,6 @@ - Sparv now respects the `JAVA_HOME` environment variable. - Added autocomplete instructions for `zsh`. - Added 'misc:fake_text_headtail' annotator. -- You can now use `from __future__ import annotations` in Sparv modules. ### Changed diff --git a/pyproject.toml b/pyproject.toml index 82a1ba75..6d12aa0d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -109,6 +109,7 @@ preview = true [tool.ruff.lint.per-file-ignores] "__init__.py" = ["F401"] # Pyflakes: unused-import +"sparv/modules/*.py" = ["FA100", "UP045"] # For Python 3.9 compatibility in modules [tool.ruff.lint.pydocstyle] convention = "google" diff --git a/sparv/modules/lexical_classes/token.py b/sparv/modules/lexical_classes/token.py index f662e125..a33d3cad 100644 --- a/sparv/modules/lexical_classes/token.py +++ b/sparv/modules/lexical_classes/token.py @@ -1,5 +1,5 @@ """Annotate words with lexical classes from Blingbring or SweFN.""" -from __future__ import annotations +from typing import Optional from sparv.api import Annotation, Config, Model, Output, annotator, get_logger, util from sparv.api.util.constants import AFFIX, DELIM, SCORESEP @@ -23,7 +23,7 @@ def blingbring_words(out: Output = Output(":lexical_classes.blingbring", delimiter: str = DELIM, affix: str = AFFIX, scoresep: str = SCORESEP, - lexicon: util.misc.PickledLexicon | None = None): + lexicon: Optional[util.misc.PickledLexicon] = None): """Blingbring specific wrapper for annotate_words. See annotate_words for more info.""" # pos_limit="NN VB JJ AB" | None @@ -62,7 +62,7 @@ def swefn_words(out: Output = Output(":lexical_classes.swefn", delimiter: str = DELIM, affix: str = AFFIX, scoresep: str = SCORESEP, - lexicon: util.misc.PickledLexicon | None = None): + lexicon: Optional[util.misc.PickledLexicon] = None): """Swefn specific wrapper for annotate_words. See annotate_words for more info.""" # SweFN annotation function diff --git a/sparv/modules/malt/malt.py b/sparv/modules/malt/malt.py index bcda579f..47a7341f 100644 --- a/sparv/modules/malt/malt.py +++ b/sparv/modules/malt/malt.py @@ -1,7 +1,6 @@ """Dependency parsing using MaltParser.""" -from __future__ import annotations - import re +from typing import Optional from sparv.api import Annotation, Binary, Config, Model, ModelOutput, Output, annotator, get_logger, modelbuilder, util @@ -61,7 +60,7 @@ def annotate(maltjar: Binary = Binary("[malt.jar]"), sentence: Annotation = Annotation(""), token: Annotation = Annotation(""), encoding: str = util.constants.UTF8, - process_dict: dict | None = None): + process_dict: Optional[dict] = None): """ Run the malt parser, in an already started process defined in process_dict, or start a new process (default). diff --git a/sparv/modules/saldo/compound.py b/sparv/modules/saldo/compound.py index e78f55b1..a5440bb3 100644 --- a/sparv/modules/saldo/compound.py +++ b/sparv/modules/saldo/compound.py @@ -1,12 +1,11 @@ """Compound analysis.""" -from __future__ import annotations - import itertools import operator import pathlib import pickle import re import time +from typing import Optional import xml.etree.ElementTree as etree from functools import reduce @@ -82,7 +81,7 @@ def annotate(out_complemgrams: Output = Output(":saldo.complemgram", compdelim: str = util.constants.COMPSEP, affix: str = util.constants.AFFIX, cutoff: bool = True, - preloaded_models: tuple | None = None): + preloaded_models: Optional[tuple] = None): """Divide compound words into prefix(es) and suffix. - out_complemgram is the resulting annotation file for compound lemgrams diff --git a/sparv/modules/sensaldo/sensaldo.py b/sparv/modules/sensaldo/sensaldo.py index c512e2e1..289b6d0c 100644 --- a/sparv/modules/sensaldo/sensaldo.py +++ b/sparv/modules/sensaldo/sensaldo.py @@ -1,5 +1,5 @@ """Sentiment annotation per token using SenSALDO.""" -from __future__ import annotations +from typing import Optional from sparv.api import Annotation, Config, Model, ModelOutput, Output, annotator, get_logger, modelbuilder, util @@ -19,7 +19,7 @@ def annotate(sense: Annotation = Annotation(""), out_scores: Output = Output(":sensaldo.sentiment_score", description="SenSALDO sentiment score"), out_labels: Output = Output(":sensaldo.sentiment_label", description="SenSALDO sentiment label"), model: Model = Model("[sensaldo.model]"), - lexicon: util.misc.PickledLexicon | None = None): + lexicon: Optional[util.misc.PickledLexicon] = None): """Assign sentiment values to tokens based on their sense annotation. When more than one sense is possible, calulate a weighted mean. diff --git a/sparv/modules/swener/swener.py b/sparv/modules/swener/swener.py index abf58173..48707f66 100644 --- a/sparv/modules/swener/swener.py +++ b/sparv/modules/swener/swener.py @@ -1,7 +1,6 @@ """Named entity tagging with SweNER.""" -from __future__ import annotations - import re +from typing import Optional import xml.etree.ElementTree as etree import xml.sax.saxutils @@ -29,7 +28,7 @@ def annotate(out_ne: Output = Output("swener.ne", cls="named_entity", descriptio sentence: Annotation = Annotation(""), token: Annotation = Annotation(""), binary: Binary = Binary("[swener.binary]"), - process_dict: dict | None = None): + process_dict: Optional[dict] = None): """Tag named entities using HFST-SweNER. SweNER is either run in an already started process defined in