1+ from __future__ import annotations
2+
13import datetime as _datetime
24
35from collections .abc import Mapping
46from typing import IO
57from typing import Iterable
6- from typing import Optional
7- from typing import Tuple
8- from typing import Union
98
109from tomlkit ._utils import parse_rfc3339
1110from tomlkit .container import Container
3433from tomlkit .toml_document import TOMLDocument
3534
3635
37- def loads (string : Union [ str , bytes ] ) -> TOMLDocument :
36+ def loads (string : str | bytes ) -> TOMLDocument :
3837 """
3938 Parses a string into a TOMLDocument.
4039
@@ -59,7 +58,7 @@ def dumps(data: Mapping, sort_keys: bool = False) -> str:
5958 raise TypeError (msg ) from ex
6059
6160
62- def load (fp : Union [ IO [str ], IO [bytes ] ]) -> TOMLDocument :
61+ def load (fp : IO [str ] | IO [bytes ]) -> TOMLDocument :
6362 """
6463 Load toml document from a file-like object.
6564 """
@@ -76,7 +75,7 @@ def dump(data: Mapping, fp: IO[str], *, sort_keys: bool = False) -> None:
7675 fp .write (dumps (data , sort_keys = sort_keys ))
7776
7877
79- def parse (string : Union [ str , bytes ] ) -> TOMLDocument :
78+ def parse (string : str | bytes ) -> TOMLDocument :
8079 """
8180 Parses a string or bytes into a TOMLDocument.
8281 """
@@ -91,12 +90,12 @@ def document() -> TOMLDocument:
9190
9291
9392# Items
94- def integer (raw : Union [ str , int ] ) -> Integer :
93+ def integer (raw : str | int ) -> Integer :
9594 """Create an integer item from a number or string."""
9695 return item (int (raw ))
9796
9897
99- def float_ (raw : Union [ str , float ] ) -> Float :
98+ def float_ (raw : str | float ) -> Float :
10099 """Create an float item from a number or string."""
101100 return item (float (raw ))
102101
@@ -175,7 +174,7 @@ def array(raw: str = None) -> Array:
175174 return value (raw )
176175
177176
178- def table (is_super_table : Optional [ bool ] = None ) -> Table :
177+ def table (is_super_table : bool | None = None ) -> Table :
179178 """Create an empty table.
180179
181180 :param is_super_table: if true, the table is a super table
@@ -224,7 +223,7 @@ def aot() -> AoT:
224223 return AoT ([])
225224
226225
227- def key (k : Union [ str , Iterable [str ] ]) -> Key :
226+ def key (k : str | Iterable [str ]) -> Key :
228227 """Create a key from a string. When a list of string is given,
229228 it will create a dotted key.
230229
@@ -261,7 +260,7 @@ def value(raw: str) -> _Item:
261260 return v
262261
263262
264- def key_value (src : str ) -> Tuple [Key , _Item ]:
263+ def key_value (src : str ) -> tuple [Key , _Item ]:
265264 """Parse a key-value pair from a string.
266265
267266 :Example:
0 commit comments