Skip to content

Commit 4486954

Browse files
committed
Use collections directly (new in 3.9)
1 parent 1d720e0 commit 4486954

File tree

6 files changed

+19
-20
lines changed

6 files changed

+19
-20
lines changed

pydifact/parser.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2121
# THE SOFTWARE.
2222
from collections.abc import Iterator
23-
from typing import List, Optional, Union
23+
from typing import Optional, Union
2424

2525
from pydifact.tokenizer import Tokenizer
2626
from pydifact.token import Token
@@ -134,10 +134,10 @@ def convert_tokens_to_segments(
134134
:rtype list of Segment
135135
"""
136136

137-
segments: List[List[Union[str, List[str]]]] = []
137+
segments: list[list[Union[str, list[str]]]] = []
138138
current_segment = []
139-
data_element: List[str] = []
140-
data_element_value: Union[List[str], str]
139+
data_element: list[str] = []
140+
data_element_value: Union[list[str], str]
141141
in_segment = False
142142
empty_component_counter = 0
143143

pydifact/segmentcollection.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import codecs
2424
import datetime
2525
from collections.abc import Callable, Iterable, Iterator, Sequence
26-
from typing import List, Optional, Tuple, Type, TypeVar, Union
26+
from typing import Optional, Type, TypeVar, Union
2727

2828
from pydifact.api import EDISyntaxError
2929
from pydifact.control import Characters
@@ -69,7 +69,7 @@ def __init__(
6969
extra_header_elements: Optional[Elements] = None,
7070
characters: Optional[Characters] = None,
7171
) -> None:
72-
self.segments: List[Segment] = []
72+
self.segments: list[Segment] = []
7373

7474
# set of control characters
7575
self.characters = characters or Characters()
@@ -198,7 +198,7 @@ def add_segments(self, segments: Iterable[Segment]) -> None:
198198
instead, without passing a ``UNA`` Segment.
199199
200200
:param segments: The segments to add.
201-
:type segments: List or iterable of :class:`~pydifact.segments.Segment` objects.
201+
:type segments: list or iterable of :class:`~pydifact.segments.Segment` objects.
202202
"""
203203
for segment in segments:
204204
self.add_segment(segment)
@@ -367,7 +367,7 @@ def __init__(
367367
sender: str,
368368
recipient: str,
369369
control_reference: str,
370-
syntax_identifier: Tuple[str, int],
370+
syntax_identifier: tuple[str, int],
371371
timestamp: Optional[datetime.datetime] = None,
372372
*args,
373373
**kwargs,

pydifact/segments.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,12 @@
2020
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2121
# THE SOFTWARE.
2222
from abc import abstractmethod
23-
from typing import Union, List
23+
from typing import Union
2424

2525
from pydifact.api import EDISyntaxError, PluginMount
26-
from pydifact.control import Characters
2726

28-
Element = Union[str, List[str], None]
29-
Elements = List[Element]
27+
Element = Union[str, list[str], None]
28+
Elements = list[Element]
3029

3130

3231
class SegmentProvider(metaclass=PluginMount):

pydifact/serializer.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2020
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2121
# THE SOFTWARE.
22-
from typing import List, Optional
22+
from typing import Optional
2323

2424
from pydifact.control.characters import Characters
2525
import re
@@ -42,7 +42,7 @@ def __init__(self, characters: Optional[Characters] = None) -> None:
4242

4343
def serialize(
4444
self,
45-
segments: List[Segment],
45+
segments: list[Segment],
4646
with_una_header: bool = True,
4747
break_lines: bool = False,
4848
) -> str:
@@ -54,7 +54,7 @@ def serialize(
5454
is created.
5555
:param break_lines: if True, insert line break after each segment terminator.
5656
"""
57-
collection_parts: List[str] = []
57+
collection_parts: list[str] = []
5858

5959
# first, check if UNA header is wanted.
6060
if with_una_header:

pydifact/tokenizer.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2121
# THE SOFTWARE.
2222
from collections.abc import Iterator
23-
from typing import Dict, List, Optional
23+
from typing import Optional
2424

2525
from pydifact.token import Token
2626
from pydifact.control.characters import Characters
@@ -35,7 +35,7 @@ def __init__(self) -> None:
3535
# The message that we are tokenizing.
3636
self._message: Iterator[str] = iter("")
3737

38-
self._current_chars: List[str] = []
38+
self._current_chars: list[str] = []
3939

4040
# The current character from the message we are dealing with.
4141
self._char: Optional[str] = ""
@@ -49,7 +49,7 @@ def __init__(self) -> None:
4949
# The control characters for the message
5050
self.characters: Optional[Characters] = None
5151

52-
self.token_selector: Dict[str, Token.Type] = {}
52+
self.token_selector: dict[str, Token.Type] = {}
5353

5454
self._message_index: int = 0
5555

tests/test_segmentcollection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# You should have received a copy of the GNU Lesser General Public License
1515
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1616
import datetime
17-
from typing import Iterable, List
17+
from typing import Iterable, list
1818

1919
import pytest
2020

@@ -79,7 +79,7 @@ def test_get_segment_w_predicate():
7979

8080

8181
def test_split_by():
82-
def _serialize(collections: Iterable[RawSegmentCollection]) -> List[List[str]]:
82+
def _serialize(collections: Iterable[RawSegmentCollection]) -> list[list[str]]:
8383
lst: list[str] = []
8484
global_lst = []
8585
for collection in collections:

0 commit comments

Comments
 (0)