Skip to content

Commit

Permalink
Changing | notation to Union[...] for 3.9 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
KasperFyhn committed May 24, 2024
1 parent 931351a commit 26e38be
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/conspiracies/common/fileutils.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import glob
import logging
from pathlib import Path
from typing import Union


def iter_lines_of_files(glob_pattern: str | Path):
def iter_lines_of_files(glob_pattern: Union[str, Path]):
if isinstance(glob_pattern, Path):
glob_pattern = glob_pattern.as_posix()
files = glob.glob(glob_pattern, recursive=True)
Expand Down
4 changes: 2 additions & 2 deletions src/conspiracies/corpusprocessing/triplet.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import json
from pathlib import Path
from typing import Optional, Set, Iterator, Iterable, List
from typing import Optional, Set, Iterator, Iterable, List, Union

from jsonlines import jsonlines
from pydantic import BaseModel
Expand Down Expand Up @@ -60,6 +60,6 @@ def from_annotated_docs(cls, path: Path) -> Iterator["Triplet"]:
)

@staticmethod
def write_jsonl(path: str | Path, triplets: Iterable["Triplet"]):
def write_jsonl(path: Union[str, Path], triplets: Iterable["Triplet"]):
with jsonlines.open(path, "w") as out:
out.write_all(map(lambda triplet: triplet.dict(), triplets))
4 changes: 2 additions & 2 deletions src/conspiracies/preprocessing/csv.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import csv
from pathlib import Path
from typing import Iterable, Iterator
from typing import Iterable, Iterator, Union

from conspiracies.common.fileutils import iter_lines_of_files
from conspiracies.document import Document
Expand Down Expand Up @@ -44,6 +44,6 @@ def _read_lines(self, lines: Iterable[str]) -> Iterator[str]:
metadata=metadata,
)

def _do_preprocess_docs(self, input_path: str | Path) -> Iterator[str]:
def _do_preprocess_docs(self, input_path: Union[str, Path]) -> Iterator[str]:
lines = iter_lines_of_files(input_path)
return self._read_lines(lines)
4 changes: 2 additions & 2 deletions src/conspiracies/preprocessing/tweets.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json
import logging
from pathlib import Path
from typing import Iterable
from typing import Iterable, Union

from conspiracies.common.fileutils import iter_lines_of_files
from conspiracies.document import Document
Expand All @@ -22,7 +22,7 @@ def __init__(
super().__init__(metadata_fields=metadata_fields)
self.context_length = context_length

def _do_preprocess_docs(self, glob_pattern: str | Path):
def _do_preprocess_docs(self, glob_pattern: Union[str, Path]) -> Iterable[str]:
lines = iter_lines_of_files(glob_pattern)
tweets = [json.loads(line) for line in lines]

Expand Down

0 comments on commit 26e38be

Please sign in to comment.