Skip to content

Commit 83dc598

Browse files
Restore Python 3.9 compatibility
1 parent 6fcc1e2 commit 83dc598

File tree

8 files changed

+35
-29
lines changed

8 files changed

+35
-29
lines changed

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ ignore = [
156156
"E501", # line too long, handled by ruff format
157157
"B008", # do not perform function calls in argument defaults
158158
"C901", # too complex
159+
"UP007", # Use X | Y for type annotations (keep Optional[X] for Python 3.9 compatibility)
160+
"UP045", # Use X | Y for type annotations (keep Optional[X] for Python 3.9 compatibility)
159161
]
160162

161163
[tool.ruff.lint.per-file-ignores]

src/pymseed/__init__.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
11
from .__version__ import __version__
22
from .clib import clibmseed, ffi
3-
43
from .definitions import (
54
DataEncoding,
6-
TimeFormat,
75
SubSecond,
6+
TimeFormat,
87
)
9-
108
from .exceptions import MiniSEEDError
119
from .msrecord import MS3Record
12-
from .msrecord_reader import MS3RecordReader
1310
from .msrecord_buffer_reader import MS3RecordBufferReader
11+
from .msrecord_reader import MS3RecordReader
1412
from .mstracelist import MS3TraceList
1513
from .util import (
16-
nstime2timestr,
17-
timestr2nstime,
18-
sourceid2nslc,
1914
nslc2sourceid,
15+
nstime2timestr,
2016
sample_time,
17+
sourceid2nslc,
18+
timestr2nstime,
2119
)
2220

2321
libmseed_version = ffi.string(clibmseed.LIBMSEED_VERSION).decode('utf-8')

src/pymseed/clib.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
44
"""
55

6-
from typing import Optional, Any
7-
6+
from typing import Any, Optional
87

98
try:
109
# This is the correct pattern: import the ffi and lib objects
1110
# directly FROM the compiled _libmseed_cffi module.
12-
from ._libmseed_cffi import ffi, lib as clibmseed
11+
from ._libmseed_cffi import ffi
12+
from ._libmseed_cffi import lib as clibmseed # noqa: F401
1313

1414
except ImportError as exc:
1515
# The friendly error message is still a good idea.

src/pymseed/definitions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
try:
1212
from .clib import clibmseed
1313
except ImportError:
14-
raise ImportError("CFFI interface not available. Please build the CFFI interface first.")
14+
raise ImportError("CFFI interface not available. Please build the CFFI interface first.") from None
1515

1616

1717
class DataEncoding(IntEnum):

src/pymseed/exceptions.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from typing import Optional
2+
23
from .util import error_string
34

45

src/pymseed/msrecord.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
from contextlib import contextmanager
99
from typing import Any, Callable, Optional, Union
1010

11-
from .clib import clibmseed, ffi, cdata_to_string
12-
from .definitions import DataEncoding, SubSecond, TimeFormat
11+
from .clib import cdata_to_string, clibmseed, ffi
12+
from .definitions import SubSecond, TimeFormat
1313
from .exceptions import MiniSEEDError
1414
from .util import encoding_string, nstime2timestr, timestr2nstime
1515

@@ -42,6 +42,7 @@ class MS3Record:
4242
FDSN:IU_COLA_00_L_H_1: 135 samples
4343
4444
Creating and writing records:
45+
>>> from pymseed import MS3Record, DataEncoding
4546
>>> record = MS3Record()
4647
>>> record.sourceid = "FDSN:NET_STA_LOC_B_S_s"
4748
>>> record.starttime_str = "2024-01-01T00:00:00Z"
@@ -454,7 +455,7 @@ def encoding(self) -> int:
454455
int: Encoding format code
455456
456457
Examples:
457-
>>> from pymseed import MS3Record
458+
>>> from pymseed import MS3Record, DataEncoding
458459
>>> record = MS3Record()
459460
>>> record.encoding = DataEncoding.STEIM2
460461
>>> record.encoding = DataEncoding.FLOAT32
@@ -780,7 +781,7 @@ def with_datasamples(self, data_samples: Sequence[Any], sample_type: str):
780781
Examples:
781782
Setting data samples for packing:
782783
783-
>>> from pymseed import MS3Record
784+
>>> from pymseed import MS3Record, DataEncoding
784785
>>> record = MS3Record()
785786
>>> record.sourceid = "FDSN:XX_TEST__L_S_X"
786787
>>> record.reclen = 512
@@ -961,6 +962,7 @@ def pack(
961962
ValueError: If sample_type is invalid or data format is incompatible
962963
963964
Examples:
965+
>>> from pymseed import MS3Record, DataEncoding
964966
>>> # Write to file
965967
>>> def file_handler(record_bytes, file_handle):
966968
... file_handle.write(record_bytes)

src/pymseed/mstracelist.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
from __future__ import annotations
77

88
from collections.abc import Sequence
9-
from typing import Any, Optional, Callable
9+
from typing import Any, Callable, Optional
1010

11-
from .clib import clibmseed, ffi, cdata_to_string
11+
from .clib import cdata_to_string, clibmseed, ffi
1212
from .definitions import DataEncoding, SubSecond, TimeFormat
1313
from .exceptions import MiniSEEDError
1414
from .msrecord import MS3Record
15-
from .util import nstime2timestr, encoding_sizetype
15+
from .util import encoding_sizetype, nstime2timestr
1616

1717

1818
class MS3RecordPtr:
@@ -100,7 +100,8 @@ def indent_repr(thing):
100100
indent_repr(self[-1]),
101101
]
102102

103-
return f"MS3RecordList(recordcnt: {len(self)}\n{'\n'.join(formatted_lines)}\n)"
103+
newline = "\n"
104+
return f"MS3RecordList(recordcnt: {len(self)}\n{newline.join(formatted_lines)}\n)"
104105

105106
def __str__(self) -> str:
106107
def indent_str(thing):
@@ -119,7 +120,8 @@ def indent_str(thing):
119120
indent_str(self[-1]),
120121
]
121122

122-
return f"Record list with {len(self)} records\n{'\n'.join(formatted_lines)}"
123+
newline = "\n"
124+
return f"Record list with {len(self)} records\n{newline.join(formatted_lines)}"
123125

124126
def __len__(self) -> int:
125127
"""Return number of records"""
@@ -567,7 +569,7 @@ def unpack_recordlist(self, buffer: Any = None, verbose: int = 0) -> int:
567569
else len(buffer)
568570
)
569571
except (TypeError, AttributeError):
570-
raise ValueError("Buffer must support the buffer protocol")
572+
raise ValueError("Buffer must support the buffer protocol") from None
571573

572574
status = clibmseed.mstl3_unpack_recordlist(
573575
self._parent_id,
@@ -582,7 +584,7 @@ def unpack_recordlist(self, buffer: Any = None, verbose: int = 0) -> int:
582584
else:
583585
return status
584586

585-
def has_same_data(self, other: "MS3TraceSeg") -> bool:
587+
def has_same_data(self, other: MS3TraceSeg) -> bool:
586588
"""Compare trace segments for equivalent data
587589
588590
Args:
@@ -637,13 +639,14 @@ def indent_repr(thing):
637639
indent_repr(self[-1]),
638640
]
639641

642+
newline = "\n"
640643
return (
641644
f"MS3TraceID(sourceid: {self.sourceid}\n"
642645
f" pubversion: {self.pubversion}\n"
643646
f" earliest: {self.earliest_str(timeformat=TimeFormat.ISOMONTHDAY_DOY_Z)}\n"
644647
f" latest: {self.latest_str(timeformat=TimeFormat.ISOMONTHDAY_DOY_Z)}\n"
645648
f" numsegments: {len(self)}\n"
646-
f"{'\n'.join(formatted_lines)}"
649+
f"{newline.join(formatted_lines)}"
647650
"\n)"
648651
)
649652

@@ -867,10 +870,8 @@ def indent_repr(thing):
867870
indent_repr(self[-1]),
868871
]
869872

870-
return (f"MS3TraceList(numtraceids: {len(self)}\n"
871-
f"{'\n'.join(formatted_lines)}\n"
872-
")"
873-
)
873+
newline = "\n"
874+
return f"MS3TraceList(numtraceids: {len(self)}\n{newline.join(formatted_lines)}\n)"
874875

875876
def __str__(self) -> str:
876877
def indent_str(thing):
@@ -889,7 +890,8 @@ def indent_str(thing):
889890
indent_str(self[-1]),
890891
]
891892

892-
return f"Trace list with {len(self)} trace IDs\n{'\n'.join(formatted_lines)}\n"
893+
newline = "\n"
894+
return f"Trace list with {len(self)} trace IDs\n{newline.join(formatted_lines)}\n"
893895

894896
def __len__(self) -> int:
895897
"""Return number of trace IDs in the list"""

src/pymseed/util.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
44
"""
55

6-
from typing import Optional, Union
6+
from typing import Optional
7+
78
from .clib import cdata_to_string, clibmseed, ffi
89
from .definitions import SubSecond, TimeFormat
910

0 commit comments

Comments
 (0)