Skip to content

Commit 4c7e524

Browse files
Abel Milashclaude
andcommitted
Replace _QB TypeVar with Self in _QueryBuilderBase fluent methods
Self (from typing, under TYPE_CHECKING) is the idiomatic replacement for the self-referential TypeVar pattern. With `from __future__ import annotations` already in place, Self is never evaluated at runtime — only used by type checkers. Method signatures in docs now show `Self` instead of the private `_QB` TypeVar. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent d43fa58 commit 4c7e524

1 file changed

Lines changed: 13 additions & 12 deletions

File tree

src/PowerPlatform/Dataverse/models/query_builder.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@
5050
from __future__ import annotations
5151

5252
import warnings
53-
from typing import Any, Iterator, List, Optional, TypeVar, TypedDict, Union
53+
from typing import TYPE_CHECKING, Any, Iterator, List, Optional, TypedDict, Union
54+
55+
if TYPE_CHECKING:
56+
from typing import Self
5457

5558
import pandas as pd
5659

@@ -62,8 +65,6 @@
6265
# Sentinel for detecting when by_page is explicitly passed to execute()
6366
_BY_PAGE_UNSET = object()
6467

65-
_QB = TypeVar("_QB", bound="_QueryBuilderBase")
66-
6768

6869
class QueryParams(TypedDict, total=False):
6970
"""Typed dictionary returned by :meth:`QueryBuilder.build`.
@@ -203,7 +204,7 @@ def __init__(self, table: str) -> None:
203204

204205
# ----------------------------------------------------------------- select
205206

206-
def select(self: _QB, *columns: str) -> _QB:
207+
def select(self, *columns: str) -> Self:
207208
"""Select specific columns to retrieve.
208209
209210
Column names are passed as-is; the OData layer lowercases them
@@ -221,7 +222,7 @@ def select(self: _QB, *columns: str) -> _QB:
221222

222223
# ------------------------------------------------------ filter: expression tree
223224

224-
def where(self: _QB, expression: filters.FilterExpression) -> _QB:
225+
def where(self, expression: filters.FilterExpression) -> Self:
225226
"""Add a composable filter expression.
226227
227228
Accepts a :class:`~PowerPlatform.Dataverse.models.filters.FilterExpression`
@@ -250,7 +251,7 @@ def where(self: _QB, expression: filters.FilterExpression) -> _QB:
250251

251252
# --------------------------------------------------------------- ordering
252253

253-
def order_by(self: _QB, column: str, descending: bool = False) -> _QB:
254+
def order_by(self, column: str, descending: bool = False) -> Self:
254255
"""Add sorting order.
255256
256257
Can be called multiple times for multi-column sorting.
@@ -265,7 +266,7 @@ def order_by(self: _QB, column: str, descending: bool = False) -> _QB:
265266

266267
# --------------------------------------------------------------- pagination
267268

268-
def top(self: _QB, count: int) -> _QB:
269+
def top(self, count: int) -> Self:
269270
"""Limit the total number of results.
270271
271272
:param count: Maximum number of records to return (must be >= 1).
@@ -277,7 +278,7 @@ def top(self: _QB, count: int) -> _QB:
277278
self._top = count
278279
return self
279280

280-
def page_size(self: _QB, size: int) -> _QB:
281+
def page_size(self, size: int) -> Self:
281282
"""Set the number of records per page.
282283
283284
Controls how many records are returned in each page/batch
@@ -292,7 +293,7 @@ def page_size(self: _QB, size: int) -> _QB:
292293
self._page_size = size
293294
return self
294295

295-
def count(self: _QB) -> _QB:
296+
def count(self) -> Self:
296297
"""Request a count of matching records in the response.
297298
298299
Adds ``$count=true`` to the query, causing the server to include
@@ -311,7 +312,7 @@ def count(self: _QB) -> _QB:
311312
self._count = True
312313
return self
313314

314-
def include_formatted_values(self: _QB) -> _QB:
315+
def include_formatted_values(self) -> Self:
315316
"""Request formatted values in the response.
316317
317318
Adds ``Prefer: odata.include-annotations="OData.Community.Display.V1.FormattedValue"``
@@ -341,7 +342,7 @@ def include_formatted_values(self: _QB) -> _QB:
341342
self._include_annotations = "OData.Community.Display.V1.FormattedValue"
342343
return self
343344

344-
def include_annotations(self: _QB, annotation: str = "*") -> _QB:
345+
def include_annotations(self, annotation: str = "*") -> Self:
345346
"""Request specific OData annotations in the response.
346347
347348
Sets the ``Prefer: odata.include-annotations`` header. Use ``"*"``
@@ -369,7 +370,7 @@ def include_annotations(self: _QB, annotation: str = "*") -> _QB:
369370

370371
# --------------------------------------------------------------- expand
371372

372-
def expand(self: _QB, *relations: Union[str, ExpandOption]) -> _QB:
373+
def expand(self, *relations: Union[str, ExpandOption]) -> Self:
373374
"""Expand navigation properties.
374375
375376
Accepts plain navigation property names (case-sensitive, passed

0 commit comments

Comments
 (0)