Skip to content

refactor: improve type hints for QuerySetSingle#2191

Open
waketzheng wants to merge 1 commit into
tortoise:developfrom
waketzheng:improve-type-hints
Open

refactor: improve type hints for QuerySetSingle#2191
waketzheng wants to merge 1 commit into
tortoise:developfrom
waketzheng:improve-type-hints

Conversation

@waketzheng
Copy link
Copy Markdown
Contributor

Description

  • demo.py
from tortoise import Model, fields


class User(Model):
    name = fields.CharField(20)


qs = User.get_or_none(name="")
print(qs.sql())
  • Run mypy demo.py got:
demo.py:9: error: "QuerySetSingle[User | None]" has no attribute "sql"  [attr-defined]
    print(qs.sql())
          ^~~~~~
Found 1 error in 1 file (checked 1 source file)

Motivation and Context

To improve type hints

How Has This Been Tested?

ci

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.

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented May 13, 2026

Merging this PR will not alter performance

✅ 24 untouched benchmarks


Comparing waketzheng:improve-type-hints (e39467b) with develop (bfb9e81)

Open in CodSpeed

Copy link
Copy Markdown
Contributor

@seladb seladb left a comment

Choose a reason for hiding this comment

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

LGTM

@waketzheng waketzheng requested a review from abondar May 15, 2026 00:29
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