3
3
"""
4
4
5
5
from __future__ import annotations
6
+ import builtins
6
7
7
8
import collections
8
9
import csv
23
24
Optional ,
24
25
TypeVar ,
25
26
Union ,
27
+ cast ,
26
28
overload ,
27
29
)
28
30
31
33
32
34
from functional import transformations
33
35
from functional .execution import ExecutionEngine , ExecutionStrategies
34
- from functional .io import WRITE_MODE , FileDescriptorOrPath , universal_write_open
36
+ from functional .io import WRITE_MODE , StrOrBytesPath , universal_write_open
35
37
from functional .lineage import Lineage
36
38
from functional .util import (
37
39
SupportsRichComparisonT ,
@@ -173,7 +175,7 @@ def __nonzero__(self) -> bool:
173
175
"""
174
176
return self .len () != 0
175
177
176
- def __getitem__ (self , item : int ) -> T | Sequence : # TODO
178
+ def __getitem__ (self , item : int ) -> T | Sequence :
177
179
"""
178
180
Gets item at given index.
179
181
@@ -212,7 +214,7 @@ def __add__(self, other) -> Sequence[T]:
212
214
else :
213
215
return Sequence (self .sequence + other , no_wrap = self .no_wrap )
214
216
215
- def _evaluate (self ) -> Iterable [ str ] :
217
+ def _evaluate (self ) -> Iterable :
216
218
"""
217
219
Creates and returns an iterator which applies all the transformations in the lineage
218
220
@@ -1483,7 +1485,7 @@ def to_dict(
1483
1485
...
1484
1486
1485
1487
def to_dict (
1486
- self : Sequence [tuple [U , V ]], default : Optional [ Callable [[], V ]] = None
1488
+ self : Sequence [tuple [U , V ]], default : Callable [[], V ] | V | None = None
1487
1489
) -> dict [U , V ] | collections .defaultdict [U , V ]:
1488
1490
"""
1489
1491
Converts sequence of (Key, Value) pairs to a dictionary.
@@ -1505,7 +1507,7 @@ def to_dict(
1505
1507
return dictionary
1506
1508
else :
1507
1509
return collections .defaultdict (
1508
- default if callable (default ) else lambda : default , dictionary
1510
+ default if callable (default ) else lambda : cast ( V , default ) , dictionary
1509
1511
)
1510
1512
1511
1513
@overload
@@ -1541,19 +1543,19 @@ def dict(
1541
1543
# pylint: disable=too-many-locals
1542
1544
def to_file (
1543
1545
self ,
1544
- path : FileDescriptorOrPath ,
1545
- delimiter = None ,
1546
- mode = "wt" ,
1547
- buffering = - 1 ,
1548
- encoding = None ,
1549
- errors = None ,
1550
- newline = None ,
1551
- compresslevel = 9 ,
1552
- format = None ,
1553
- check = - 1 ,
1554
- preset = None ,
1555
- filters = None ,
1556
- compression = None ,
1546
+ path : StrOrBytesPath ,
1547
+ delimiter : Optional [ str ] = None ,
1548
+ mode : str = "wt" ,
1549
+ buffering : int = - 1 ,
1550
+ encoding : Optional [ str ] = None ,
1551
+ errors : Optional [ str ] = None ,
1552
+ newline : Optional [ str ] = None ,
1553
+ compresslevel : int = 9 ,
1554
+ format : Optional [ int ] = None ,
1555
+ check : int = - 1 ,
1556
+ preset : Optional [ int ] = None ,
1557
+ filters : Optional [ Iterable [ builtins . dict ]] = None ,
1558
+ compression : Optional [ str ] = None ,
1557
1559
):
1558
1560
"""
1559
1561
Saves the sequence to a file by executing str(self) which becomes str(self.to_list()). If
@@ -1594,9 +1596,9 @@ def to_file(
1594
1596
1595
1597
def to_jsonl (
1596
1598
self ,
1597
- path : FileDescriptorOrPath ,
1599
+ path : StrOrBytesPath ,
1598
1600
mode : str = "wb" ,
1599
- compression : Optional [bool ] = None ,
1601
+ compression : Optional [str ] = None ,
1600
1602
):
1601
1603
"""
1602
1604
Saves the sequence to a jsonl file. Each element is mapped using json.dumps then written
0 commit comments