|
3 | 3 | import base64
|
4 | 4 | import os
|
5 | 5 | from pathlib import Path
|
| 6 | +from typing import Optional, Union |
6 | 7 |
|
7 | 8 | from monty.json import MSONable
|
8 | 9 | from typing_extensions import Self
|
|
11 | 12 | class AbinitStoredFile(MSONable):
|
12 | 13 | """Wrap a file to store its raw data."""
|
13 | 14 |
|
14 |
| - def __init__(self, data: str | bytes, source_filepath: str | Path) -> None: |
| 15 | + def __init__( |
| 16 | + self, data: Union[str, bytes], source_filepath: Union[str, Path] |
| 17 | + ) -> None: |
15 | 18 | self.data = data
|
16 | 19 | self.source_filepath = source_filepath
|
17 | 20 |
|
@@ -39,7 +42,7 @@ def from_dict(cls, d: dict) -> Self:
|
39 | 42 | return cls(data=data, source_filepath=d["source_filepath"])
|
40 | 43 |
|
41 | 44 | @classmethod
|
42 |
| - def from_file(cls, filepath: str | Path, data_type: str | type) -> Self: |
| 45 | + def from_file(cls, filepath: Union[str, Path], data_type: Union[str, type]) -> Self: |
43 | 46 | """Create an AbinitStoredFile from the original file."""
|
44 | 47 | source_filepath = os.path.abspath(filepath)
|
45 | 48 | if data_type in {"bytes", bytes}:
|
@@ -68,7 +71,7 @@ def extension(self) -> str:
|
68 | 71 | """Return the extension of the source file."""
|
69 | 72 | return str(self.source_filepath).split("_")[-1]
|
70 | 73 |
|
71 |
| - def write(self, filepath: str | Path = None) -> None: |
| 74 | + def write(self, filepath: Optional[Union[str, Path]] = None) -> None: |
72 | 75 | """Write the data into a file."""
|
73 | 76 | filepath = filepath or self.filename
|
74 | 77 | if self.data_type == "bytes":
|
|
0 commit comments