Skip to content

Commit

Permalink
Remove usage of modern type hints in annotator signatures for compati…
Browse files Browse the repository at this point in the history
…bility
  • Loading branch information
MartinHammarstedt committed Jan 27, 2025
1 parent e406888 commit 9e20709
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 15 deletions.
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions sparv/modules/lexical_classes/token.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -23,7 +23,7 @@ def blingbring_words(out: Output = Output("<token>: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

Expand Down Expand Up @@ -62,7 +62,7 @@ def swefn_words(out: Output = Output("<token>: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
Expand Down
5 changes: 2 additions & 3 deletions sparv/modules/malt/malt.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -61,7 +60,7 @@ def annotate(maltjar: Binary = Binary("[malt.jar]"),
sentence: Annotation = Annotation("<sentence>"),
token: Annotation = Annotation("<token>"),
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).
Expand Down
5 changes: 2 additions & 3 deletions sparv/modules/saldo/compound.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -82,7 +81,7 @@ def annotate(out_complemgrams: Output = Output("<token>: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
Expand Down
4 changes: 2 additions & 2 deletions sparv/modules/sensaldo/sensaldo.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -19,7 +19,7 @@ def annotate(sense: Annotation = Annotation("<token:sense>"),
out_scores: Output = Output("<token>:sensaldo.sentiment_score", description="SenSALDO sentiment score"),
out_labels: Output = Output("<token>: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.
Expand Down
5 changes: 2 additions & 3 deletions sparv/modules/swener/swener.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -29,7 +28,7 @@ def annotate(out_ne: Output = Output("swener.ne", cls="named_entity", descriptio
sentence: Annotation = Annotation("<sentence>"),
token: Annotation = Annotation("<token>"),
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
Expand Down

0 comments on commit 9e20709

Please sign in to comment.