macss-modular-api-sqlserver 0.6.0__tar.gz → 0.7.0__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.
Files changed (15) hide show
  1. {macss_modular_api_sqlserver-0.6.0 → macss_modular_api_sqlserver-0.7.0}/PKG-INFO +2 -1
  2. macss_modular_api_sqlserver-0.7.0/pyproject.toml +85 -0
  3. {macss_modular_api_sqlserver-0.6.0 → macss_modular_api_sqlserver-0.7.0}/src/macss_modular_api_sqlserver.egg-info/PKG-INFO +2 -1
  4. {macss_modular_api_sqlserver-0.6.0 → macss_modular_api_sqlserver-0.7.0}/src/macss_modular_api_sqlserver.egg-info/SOURCES.txt +1 -0
  5. {macss_modular_api_sqlserver-0.6.0 → macss_modular_api_sqlserver-0.7.0}/src/macss_modular_api_sqlserver.egg-info/requires.txt +1 -0
  6. {macss_modular_api_sqlserver-0.6.0 → macss_modular_api_sqlserver-0.7.0}/src/modular_api_sqlserver/db_client.py +34 -34
  7. macss_modular_api_sqlserver-0.7.0/src/modular_api_sqlserver/py.typed +0 -0
  8. {macss_modular_api_sqlserver-0.6.0 → macss_modular_api_sqlserver-0.7.0}/tests/test_db_client.py +16 -3
  9. {macss_modular_api_sqlserver-0.6.0 → macss_modular_api_sqlserver-0.7.0}/tests/test_db_conformance.py +6 -3
  10. macss_modular_api_sqlserver-0.6.0/pyproject.toml +0 -46
  11. {macss_modular_api_sqlserver-0.6.0 → macss_modular_api_sqlserver-0.7.0}/README.md +0 -0
  12. {macss_modular_api_sqlserver-0.6.0 → macss_modular_api_sqlserver-0.7.0}/setup.cfg +0 -0
  13. {macss_modular_api_sqlserver-0.6.0 → macss_modular_api_sqlserver-0.7.0}/src/macss_modular_api_sqlserver.egg-info/dependency_links.txt +0 -0
  14. {macss_modular_api_sqlserver-0.6.0 → macss_modular_api_sqlserver-0.7.0}/src/macss_modular_api_sqlserver.egg-info/top_level.txt +0 -0
  15. {macss_modular_api_sqlserver-0.6.0 → macss_modular_api_sqlserver-0.7.0}/src/modular_api_sqlserver/__init__.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: macss-modular-api-sqlserver
3
- Version: 0.6.0
3
+ Version: 0.7.0
4
4
  Summary: Official MACSS SQL Server integration package for Python.
5
5
  Author: ccisne.dev
6
6
  License-Expression: MIT
@@ -20,6 +20,7 @@ Classifier: Typing :: Typed
20
20
  Requires-Python: >=3.11
21
21
  Description-Content-Type: text/markdown
22
22
  Provides-Extra: dev
23
+ Requires-Dist: pyright>=1.1.400; extra == "dev"
23
24
  Requires-Dist: pytest>=8.0; extra == "dev"
24
25
 
25
26
  # macss-modular-api-sqlserver
@@ -0,0 +1,85 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "macss-modular-api-sqlserver"
7
+ version = "0.7.0"
8
+ description = "Official MACSS SQL Server integration package for Python."
9
+ readme = "README.md"
10
+ license = "MIT"
11
+ requires-python = ">=3.11"
12
+ authors = [{ name = "ccisne.dev" }]
13
+ keywords = ["macss", "sqlserver", "database"]
14
+ classifiers = [
15
+ "Development Status :: 4 - Beta",
16
+ "Intended Audience :: Developers",
17
+ "Programming Language :: Python :: 3",
18
+ "Programming Language :: Python :: 3.11",
19
+ "Programming Language :: Python :: 3.12",
20
+ "Programming Language :: Python :: 3.13",
21
+ "Topic :: Database",
22
+ "Typing :: Typed",
23
+ ]
24
+ dependencies = []
25
+
26
+ [project.optional-dependencies]
27
+ dev = [
28
+ # Configured below at `typeCheckingMode = "strict"`. Declared here because a checker the
29
+ # repo configures and never installs is a checker that has never run.
30
+ "pyright>=1.1.400",
31
+ "pytest>=8.0",
32
+ ]
33
+
34
+ [project.urls]
35
+ Homepage = "https://github.com/macss-dev/modular_api"
36
+ Repository = "https://github.com/macss-dev/modular_api/tree/main/code/py/modular_api_sqlserver"
37
+ Issues = "https://github.com/macss-dev/modular_api/issues"
38
+ Documentation = "https://github.com/macss-dev/modular_api/tree/main/code/py/modular_api_sqlserver#readme"
39
+
40
+ [tool.setuptools.packages.find]
41
+ where = ["src"]
42
+
43
+ [tool.pytest.ini_options]
44
+ testpaths = ["tests"]
45
+ pythonpath = ["src"]
46
+
47
+ [tool.pyright]
48
+ pythonVersion = "3.11"
49
+ # `src/` is checked at full strict, because it is what a consumer's own type checker sees: these
50
+ # packages ship `py.typed`, so every annotation here becomes part of the public contract.
51
+ typeCheckingMode = "strict"
52
+
53
+ # `tests/` is strict too, minus the family that means "annotate this expression". Test code binds
54
+ # only this repo, and most of those diagnostics come from incomplete third-party stubs — annotating
55
+ # around them adds noise to a test without making anything more correct. Everything that can indicate
56
+ # a real defect stays on.
57
+ [[tool.pyright.executionEnvironments]]
58
+ root = "tests"
59
+ reportUnknownMemberType = false
60
+ reportUnknownArgumentType = false
61
+ reportUnknownVariableType = false
62
+ reportUnknownParameterType = false
63
+ reportUnknownLambdaType = false
64
+ reportMissingParameterType = false
65
+ reportMissingTypeArgument = false
66
+ # A pytest fixture is called by name through collection, never by a reference the checker can see, so
67
+ # `reportUnusedFunction` reports every `autouse` fixture in this tree. That is the tool not modelling
68
+ # pytest, not dead code. `reportUnusedImport` and `reportUnusedVariable` stay on — those do find dead
69
+ # code, and they did.
70
+ reportUnusedFunction = false
71
+ reportUnusedClass = false
72
+ # Tests legitimately reach into internals to exercise them directly. In `src/` this rule found real
73
+ # coupling and it was fixed rather than silenced.
74
+ reportPrivateUsage = false
75
+ # `example/` is documentation a consumer copies, not a published typed surface — same relaxed family
76
+ # as `tests/`, and the same expectation that nothing which can indicate a real defect is silenced.
77
+ [[tool.pyright.executionEnvironments]]
78
+ root = "example"
79
+ reportUnknownMemberType = false
80
+ reportUnknownArgumentType = false
81
+ reportUnknownVariableType = false
82
+ reportUnknownParameterType = false
83
+ reportUnknownLambdaType = false
84
+ reportMissingParameterType = false
85
+ reportMissingTypeArgument = false
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: macss-modular-api-sqlserver
3
- Version: 0.6.0
3
+ Version: 0.7.0
4
4
  Summary: Official MACSS SQL Server integration package for Python.
5
5
  Author: ccisne.dev
6
6
  License-Expression: MIT
@@ -20,6 +20,7 @@ Classifier: Typing :: Typed
20
20
  Requires-Python: >=3.11
21
21
  Description-Content-Type: text/markdown
22
22
  Provides-Extra: dev
23
+ Requires-Dist: pyright>=1.1.400; extra == "dev"
23
24
  Requires-Dist: pytest>=8.0; extra == "dev"
24
25
 
25
26
  # macss-modular-api-sqlserver
@@ -7,5 +7,6 @@ src/macss_modular_api_sqlserver.egg-info/requires.txt
7
7
  src/macss_modular_api_sqlserver.egg-info/top_level.txt
8
8
  src/modular_api_sqlserver/__init__.py
9
9
  src/modular_api_sqlserver/db_client.py
10
+ src/modular_api_sqlserver/py.typed
10
11
  tests/test_db_client.py
11
12
  tests/test_db_conformance.py
@@ -4,9 +4,11 @@ import os
4
4
  import time
5
5
  from dataclasses import dataclass, field
6
6
  from enum import Enum
7
- from typing import Any, Callable, Generic, Mapping, Protocol, TypeVar, cast
7
+ from typing import Callable, Generic, Mapping, Protocol, TypeVar, cast
8
8
 
9
9
  S = TypeVar("S")
10
+ #: Contravariant because the protocols below only ever *accept* a session, never return one.
11
+ S_contra = TypeVar("S_contra", contravariant=True)
10
12
  T = TypeVar("T")
11
13
  R = TypeVar("R")
12
14
  _MISSING = object()
@@ -52,7 +54,7 @@ class DbConnectionSettings:
52
54
  username: str
53
55
  password: str
54
56
  driver: str
55
- options: Mapping[str, object] = field(default_factory=dict)
57
+ options: Mapping[str, object] = field(default_factory=dict[str, object])
56
58
 
57
59
  @classmethod
58
60
  def from_environment(
@@ -206,18 +208,18 @@ class DbResult(Generic[T]):
206
208
 
207
209
  def map(self, transform: Callable[[T], R]) -> DbResult[R]:
208
210
  if self.is_failure:
209
- return DbResult.from_failure(self.failure)
210
- return DbResult.success(transform(self.value))
211
+ return DbResult[R].from_failure(self.failure)
212
+ return DbResult[R].success(transform(self.value))
211
213
 
212
214
  def flat_map(self, transform: Callable[[T], DbResult[R]]) -> DbResult[R]:
213
215
  if self.is_failure:
214
- return DbResult.from_failure(self.failure)
216
+ return DbResult[R].from_failure(self.failure)
215
217
  return transform(self.value)
216
218
 
217
219
  def map_failure(self, transform: Callable[[DbFailure], DbFailure]) -> DbResult[T]:
218
220
  if self.is_success:
219
- return DbResult.success(self.value)
220
- return DbResult.from_failure(transform(self.failure))
221
+ return DbResult[T].success(self.value)
222
+ return DbResult[T].from_failure(transform(self.failure))
221
223
 
222
224
  def get_or_throw(self, message: str | None = None) -> T:
223
225
  if self.is_failure:
@@ -247,7 +249,7 @@ class DbSessionLease(Generic[S]):
247
249
 
248
250
  def release(self) -> DbResult[None]:
249
251
  if not self.owned_by_package:
250
- return DbResult.success(None)
252
+ return DbResult[None].success(None)
251
253
  return self._releaser()
252
254
 
253
255
 
@@ -259,12 +261,16 @@ class DbSessionProvider(Protocol[S]):
259
261
  def describe(self) -> DbProviderDescription: ...
260
262
 
261
263
 
262
- class DbCommandExecutor(Protocol[S]):
263
- def query(self, session: S, command: DbCommand) -> DbResult[DbRowSet]: ...
264
+ class DbCommandExecutor(Protocol[S_contra]):
265
+ def query(self, session: S_contra, command: DbCommand) -> DbResult[DbRowSet]: ...
264
266
 
265
- def execute(self, session: S, command: DbCommand) -> DbResult[DbExecutionSummary]: ...
267
+ def execute(
268
+ self, session: S_contra, command: DbCommand
269
+ ) -> DbResult[DbExecutionSummary]: ...
266
270
 
267
- def scalar(self, session: S, command: DbCommand) -> DbResult[DbScalar[object]]: ...
271
+ def scalar(
272
+ self, session: S_contra, command: DbCommand
273
+ ) -> DbResult[DbScalar[object]]: ...
268
274
 
269
275
 
270
276
  @dataclass(frozen=True, slots=True)
@@ -279,8 +285,8 @@ class DbTransactionContext(Generic[S]):
279
285
  def execute(self, command: DbCommand) -> DbResult[DbExecutionSummary]:
280
286
  return self.command_executor.execute(self.session, command)
281
287
 
282
- def scalar(self, command: DbCommand) -> DbResult[DbScalar[T]]:
283
- return cast(DbResult[DbScalar[T]], self.command_executor.scalar(self.session, command))
288
+ def scalar(self, command: DbCommand) -> DbResult[DbScalar[object]]:
289
+ return self.command_executor.scalar(self.session, command)
284
290
 
285
291
 
286
292
  class DbTransactionRunner(Protocol[S]):
@@ -315,13 +321,10 @@ class DbRepository(Generic[S]):
315
321
  lambda lease: self.context.command_executor.execute(lease.session, command),
316
322
  )
317
323
 
318
- def scalar(self, command: DbCommand) -> DbResult[DbScalar[T]]:
319
- return cast(
320
- DbResult[DbScalar[T]],
321
- _with_lease(
322
- self.context.session_provider,
323
- lambda lease: self.context.command_executor.scalar(lease.session, command),
324
- ),
324
+ def scalar(self, command: DbCommand) -> DbResult[DbScalar[object]]:
325
+ return _with_lease(
326
+ self.context.session_provider,
327
+ lambda lease: self.context.command_executor.scalar(lease.session, command),
325
328
  )
326
329
 
327
330
  def transaction(self, body: Callable[[DbTransactionContext[S]], DbResult[T]]) -> DbResult[T]:
@@ -360,19 +363,16 @@ class DbClient(Generic[S]):
360
363
  lambda lease: self.command_executor.execute(lease.session, command),
361
364
  )
362
365
 
363
- def scalar(self, command: DbCommand) -> DbResult[DbScalar[T]]:
364
- return cast(
365
- DbResult[DbScalar[T]],
366
- _with_lease(
367
- self.session_provider,
368
- lambda lease: self.command_executor.scalar(lease.session, command),
369
- ),
366
+ def scalar(self, command: DbCommand) -> DbResult[DbScalar[object]]:
367
+ return _with_lease(
368
+ self.session_provider,
369
+ lambda lease: self.command_executor.scalar(lease.session, command),
370
370
  )
371
371
 
372
372
  def transaction(self, body: Callable[[DbTransactionContext[S]], DbResult[T]]) -> DbResult[T]:
373
373
  lease_result = self.session_provider.acquire()
374
374
  if lease_result.is_failure:
375
- return DbResult.from_failure(lease_result.failure)
375
+ return DbResult[T].from_failure(lease_result.failure)
376
376
 
377
377
  lease = lease_result.value
378
378
  context = DbTransactionContext(
@@ -384,9 +384,9 @@ class DbClient(Generic[S]):
384
384
  release_result = lease.release()
385
385
 
386
386
  if result.is_failure:
387
- return DbResult.from_failure(result.failure)
387
+ return DbResult[T].from_failure(result.failure)
388
388
  if release_result.is_failure:
389
- return DbResult.from_failure(release_result.failure)
389
+ return DbResult[T].from_failure(release_result.failure)
390
390
  return result
391
391
 
392
392
  def repository_context(self) -> DbRepositoryContext[S]:
@@ -457,14 +457,14 @@ def _with_lease(
457
457
  ) -> DbResult[T]:
458
458
  lease_result = session_provider.acquire()
459
459
  if lease_result.is_failure:
460
- return DbResult.from_failure(lease_result.failure)
460
+ return DbResult[T].from_failure(lease_result.failure)
461
461
 
462
462
  lease = lease_result.value
463
463
  operation_result = operation(lease)
464
464
  release_result = lease.release()
465
465
 
466
466
  if operation_result.is_failure:
467
- return DbResult.from_failure(operation_result.failure)
467
+ return DbResult[T].from_failure(operation_result.failure)
468
468
  if release_result.is_failure:
469
- return DbResult.from_failure(release_result.failure)
469
+ return DbResult[T].from_failure(release_result.failure)
470
470
  return operation_result
@@ -4,6 +4,11 @@ from dataclasses import dataclass
4
4
 
5
5
  import pytest
6
6
 
7
+ from collections.abc import Callable
8
+ from typing import TypeVar, cast
9
+
10
+ _T = TypeVar("_T")
11
+
7
12
  from modular_api_sqlserver import (
8
13
  DbClient,
9
14
  DbCommand,
@@ -114,6 +119,7 @@ def test_client_delegates_query_calls_and_releases_package_owned_leases() -> Non
114
119
  assert provider.acquire_count == 1
115
120
  assert provider.release_count == 1
116
121
  assert executor.last_session == "db-session"
122
+ assert executor.last_command is not None
117
123
  assert executor.last_command.label == "users.list"
118
124
 
119
125
 
@@ -302,6 +308,7 @@ def test_repository_helpers_stay_thin_over_the_shared_context() -> None:
302
308
 
303
309
  assert result.is_success is True
304
310
  assert result.value == 9
311
+ assert executor.last_command is not None
305
312
  assert executor.last_command.label == "users.count"
306
313
 
307
314
 
@@ -457,8 +464,12 @@ class _FakeTransactionRunner:
457
464
  def run(
458
465
  self,
459
466
  context: DbTransactionContext[str],
460
- body: callable,
461
- ) -> DbResult[object]:
467
+ # Two fixes in one signature. `callable` is the builtin predicate, not a type — annotating with
468
+ # it left this fake failing to satisfy `DbTransactionRunner[str]`, which is the whole point of a
469
+ # fake. And `run` is generic in the body's result: pinning it to `object` still would not have
470
+ # satisfied the protocol, because a runner is transparent in what the body returns.
471
+ body: Callable[[DbTransactionContext[str]], DbResult[_T]],
472
+ ) -> DbResult[_T]:
462
473
  result = body(context)
463
474
  if result.is_success:
464
475
  self.commit_count += 1
@@ -476,7 +487,9 @@ class _UserStatsRepository(DbRepository[str]):
476
487
  label="users.count",
477
488
  )
478
489
  )
479
- return result.map(lambda value: int(value.value))
490
+ # `scalar()` yields `DbScalar[object]`: Python cannot parameterise a method call the way Dart
491
+ # and TypeScript can, so a consumer narrows the value it knows its own query returns.
492
+ return result.map(lambda value: int(cast("int | str", value.value)))
480
493
 
481
494
 
482
495
  # --- 0.6.0: typed parameters and stored-procedure support ---
@@ -2,6 +2,7 @@ from __future__ import annotations
2
2
 
3
3
  import json
4
4
  from pathlib import Path
5
+ from typing import Any, cast
5
6
 
6
7
  from modular_api_sqlserver import (
7
8
  DbCommand,
@@ -15,12 +16,14 @@ from modular_api_sqlserver import (
15
16
  )
16
17
 
17
18
 
18
- def _load_fixture() -> dict[str, object]:
19
- return json.loads(
19
+ def _load_fixture() -> dict[str, Any]:
20
+ # `dict[str, Any]`, not `dict[str, object]`: every read below walks into the fixture, and `object`
21
+ # stops at the first subscript. The values really are arbitrary JSON.
22
+ return cast("dict[str, Any]", json.loads(
20
23
  (Path(__file__).resolve().parents[3] / "tests" / "fixtures" / "db_client" / "sqlserver.json").read_text(
21
24
  encoding="utf-8"
22
25
  )
23
- )
26
+ ))
24
27
 
25
28
 
26
29
  def test_matches_the_shared_sqlserver_connection_fixture() -> None:
@@ -1,46 +0,0 @@
1
- [build-system]
2
- requires = ["setuptools>=68", "wheel"]
3
- build-backend = "setuptools.build_meta"
4
-
5
- [project]
6
- name = "macss-modular-api-sqlserver"
7
- version = "0.6.0"
8
- description = "Official MACSS SQL Server integration package for Python."
9
- readme = "README.md"
10
- license = "MIT"
11
- requires-python = ">=3.11"
12
- authors = [{ name = "ccisne.dev" }]
13
- keywords = ["macss", "sqlserver", "database"]
14
- classifiers = [
15
- "Development Status :: 4 - Beta",
16
- "Intended Audience :: Developers",
17
- "Programming Language :: Python :: 3",
18
- "Programming Language :: Python :: 3.11",
19
- "Programming Language :: Python :: 3.12",
20
- "Programming Language :: Python :: 3.13",
21
- "Topic :: Database",
22
- "Typing :: Typed",
23
- ]
24
- dependencies = []
25
-
26
- [project.optional-dependencies]
27
- dev = [
28
- "pytest>=8.0",
29
- ]
30
-
31
- [project.urls]
32
- Homepage = "https://github.com/macss-dev/modular_api"
33
- Repository = "https://github.com/macss-dev/modular_api/tree/main/code/py/modular_api_sqlserver"
34
- Issues = "https://github.com/macss-dev/modular_api/issues"
35
- Documentation = "https://github.com/macss-dev/modular_api/tree/main/code/py/modular_api_sqlserver#readme"
36
-
37
- [tool.setuptools.packages.find]
38
- where = ["src"]
39
-
40
- [tool.pytest.ini_options]
41
- testpaths = ["tests"]
42
- pythonpath = ["src"]
43
-
44
- [tool.pyright]
45
- pythonVersion = "3.11"
46
- typeCheckingMode = "strict"