flpit 0.2.1.dev4__tar.gz → 0.2.1.dev6__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: flpit
3
- Version: 0.2.1.dev4
3
+ Version: 0.2.1.dev6
4
4
  Summary: Fluent LINQ for Python — flip your iterables
5
5
  Project-URL: Homepage, https://github.com/riemar/flpit
6
6
  Project-URL: Repository, https://github.com/riemar/flpit
@@ -14,6 +14,7 @@ Classifier: Programming Language :: Python :: 3
14
14
  Classifier: Programming Language :: Python :: 3.12
15
15
  Classifier: Programming Language :: Python :: 3.13
16
16
  Classifier: Programming Language :: Python :: 3.14
17
+ Classifier: Programming Language :: Python :: 3.15
17
18
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
18
19
  Classifier: Typing :: Typed
19
20
  Requires-Python: >=3.12
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "flpit"
3
- version = "0.2.1.dev4"
3
+ version = "0.2.1.dev6"
4
4
  description = "Fluent LINQ for Python — flip your iterables"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.12"
@@ -14,6 +14,7 @@ classifiers = [
14
14
  "Programming Language :: Python :: 3.12",
15
15
  "Programming Language :: Python :: 3.13",
16
16
  "Programming Language :: Python :: 3.14",
17
+ "Programming Language :: Python :: 3.15",
17
18
  "Topic :: Software Development :: Libraries :: Python Modules",
18
19
  "Typing :: Typed"
19
20
  ]
@@ -1,6 +1,10 @@
1
- from flpit.io import StringWriter
1
+ from __future__ import annotations
2
+
3
+ from io import BytesIO, StringIO
4
+
2
5
  import decimal
3
6
  from decimal import Decimal, Overflow, Inexact
7
+ from contextlib import AbstractContextManager
4
8
 
5
9
  import builtins
6
10
  from collections import UserList
@@ -23,11 +27,9 @@ from typing import (
23
27
  Union,
24
28
  override,
25
29
  overload,
26
- cast as typing_cast,
27
- GenericAlias
30
+ cast as typing_cast, BinaryIO,
28
31
  )
29
32
 
30
- from flpit.io import MemoryByteWriter
31
33
  from flpit.json import JsonConvert, JsonSerializerOptions
32
34
 
33
35
  TItem = TypeVar("TItem")
@@ -124,8 +126,7 @@ def _guard_empty(func: Callable[..., Any]) -> Callable[..., Any]:
124
126
  return wrapper
125
127
 
126
128
 
127
- # noinspection unresolved-references,protected-member
128
- def dotnet_context() -> decimal._ContextManager: # awesome that type was not intended
129
+ def dotnet_context() -> AbstractContextManager[decimal.Context]:
129
130
  # 1. Create and configure pure Context object
130
131
  ctx = decimal.getcontext().copy()
131
132
  ctx.prec = max(ctx.prec, 29)
@@ -636,15 +637,23 @@ class FlpIt(Iterable[TItem], Generic[TItem]):
636
637
  return FlpIt[T](JsonConvert.deserialize(data, list[item_type], jso))
637
638
 
638
639
  def to_json_bytes[T](self, item_type: type[T], jso: JsonSerializerOptions|None=None) -> bytes:
639
- writer = MemoryByteWriter()
640
+ writer = BytesIO()
640
641
  JsonConvert.serialize_to(self, item_type, writer, jso)
641
642
  return writer.getvalue()
642
643
 
643
644
  def to_json[T](self, item_type: type[T], jso: JsonSerializerOptions|None=None) -> str:
644
- writer = StringWriter()
645
+ writer = StringIO()
645
646
  JsonConvert.serialize_to(self, item_type, writer, jso)
646
647
  return writer.getvalue()
647
648
 
649
+ def write_json[T](
650
+ self,
651
+ item_type: type[T],
652
+ output: BinaryIO,
653
+ jso: JsonSerializerOptions | None = None,
654
+ ) -> None:
655
+ JsonConvert.serialize_to(self, item_type, output, jso)
656
+
648
657
 
649
658
  from functools import partial
650
659
 
@@ -1220,4 +1229,10 @@ class FlpList(Collection[TItem], Generic[TItem]):
1220
1229
  def to_json[T](self, item_type: type[T], jso: JsonSerializerOptions|None=None) -> str:
1221
1230
  return JsonConvert.serialize(self.__list.data, list[item_type], jso)
1222
1231
 
1223
-
1232
+ def write_json[T](
1233
+ self,
1234
+ item_type: type[T],
1235
+ output: BinaryIO,
1236
+ jso: JsonSerializerOptions | None = None,
1237
+ ) -> None:
1238
+ JsonConvert.serialize_to(self, item_type, output, jso)
@@ -1,3 +1,5 @@
1
+ from __future__ import annotations
2
+
1
3
  from collections.abc import Iterable
2
4
  import dataclasses
3
5
  import re
@@ -9,12 +11,10 @@ from dataclasses import MISSING, dataclass
9
11
  from enum import StrEnum
10
12
  from functools import lru_cache
11
13
  from hashlib import blake2s
12
- from typing import Annotated, Any, ForwardRef, get_args, get_origin, get_type_hints, Callable, cast as typing_cast
14
+ from typing import Annotated, Any, ForwardRef, get_args, get_origin, get_type_hints, Callable
13
15
 
14
16
  import msgspec
15
17
 
16
- from flpit.io import ByteWriter, TextWriter
17
-
18
18
 
19
19
  class JsonNamingPolicy(StrEnum):
20
20
  lower = "lower" # pyrefly: ignore [bad-override-mutable-attribute]
@@ -600,17 +600,23 @@ class JsonConvert:
600
600
  def serialize_to[T](
601
601
  it: Iterable[T],
602
602
  target: type[T],
603
- output: ByteWriter | TextWriter,
604
- jso: JsonSerializerOptions | None = None
603
+ output: typing.BinaryIO | typing.TextIO,
604
+ jso: JsonSerializerOptions | None = None,
605
605
  ) -> None:
606
+ import io
606
607
  if jso is None:
607
608
  jso = JsonSerializerOptions()
608
609
 
609
- if isinstance(output, ByteWriter):
610
- write = output.write
611
- elif isinstance(output, TextWriter):
612
- def write(data: bytes | bytearray) -> int:
613
- return output.write(data.decode("utf-8"))
610
+ if isinstance(output, io.TextIOBase):
611
+ def write(data: bytes) -> None:
612
+ output.write(data.decode("utf-8"))
613
+
614
+ elif isinstance(
615
+ output,
616
+ (io.BufferedIOBase, io.RawIOBase),
617
+ ):
618
+ def write(data: bytes) -> None:
619
+ output.write(data)
614
620
  else:
615
621
  raise TypeError("output must be ByteWriter or TextWriter")
616
622