Skip to content

Typed **kwargs on field constructors#2218

Open
vlakius wants to merge 6 commits into
tortoise:developfrom
vlakius:develop
Open

Typed **kwargs on field constructors#2218
vlakius wants to merge 6 commits into
tortoise:developfrom
vlakius:develop

Conversation

@vlakius

@vlakius vlakius commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Description

Added PEP 692 Unpack[TypedDict] typing to field constructors. **kwargs: Any no longer hides common field args from IDEs/type-checkers.

Motivation and Context

See issue: #2168

How Has This Been Tested?

Checked with MyPy and PyRight and my IDE.
tried to add a typo (es: defualt) and it gets flagged as error

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added the changelog accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@vlakius vlakius changed the title updated changelog Typed **kwargs on field constructors Jun 15, 2026
@codspeed-hq

codspeed-hq Bot commented Jun 15, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 24 untouched benchmarks


Comparing vlakius:develop (538d1f9) with develop (5c79e51)

Open in CodSpeed

Comment thread tortoise/fields/data.py Outdated
_FieldKwargsNoPk,
)

if sys.version_info >= (3, 11):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about moving it under TYPE_CHECKING?

Comment thread tortoise/fields/data.py
from tortoise.models import Model


if sys.version_info >= (3, 11):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In favor of the from __future__ import annotations, this code can be written as:

if TYPE_CHECKING:  # pragma: nocoverage
    from tortoise.models import Model

    if sys.version_info >= (3, 11):
        from typing import Unpack
    else:
        from typing_extensions import Unpack

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants