Skip to content

Enable type checking for trino.client and trino.dbapi - #638

Closed
azawlocki-sbdt wants to merge 1 commit into
trinodb:masterfrom
azawlocki-sbdt:azawlocki/fix-type-annotations
Closed

Enable type checking for trino.client and trino.dbapi#638
azawlocki-sbdt wants to merge 1 commit into
trinodb:masterfrom
azawlocki-sbdt:azawlocki/fix-type-annotations

Conversation

@azawlocki-sbdt

Copy link
Copy Markdown
Contributor

Fix type annotations so that mypy can check trino.client and trino.dbapi without any type violations.

Behavioral changes:

  • When called before cursor.execute():
    • iter(cursor) now raises ProgrammingError instead of TypeError: iter() returned non-iterator of type 'NoneType'
    • cursor.fetchone()/fetchmany()/fetchall() now raise ProgrammingError instead of AssertionError (TypeError with -O)
    • cursor.genall() now raises ProgrammingError instead of AttributeError
  • TrinoRequest(max_attempts=n) with n < 1 now raises ValueError, instead of failing on first request with UnboundLocalError.

Fixes:

  • trino.dbapi.TimeFromTicks() now works correctly, previously it tried to use undefined datetime.localtime
  • TrinoUserError() can be formatted, previously str(error) raised AtttributeError

Description

Non-technical explanation

Release notes

( ) This is not user-visible or docs only and no release notes are required.
( ) Release notes are required, please propose a release note for me.
( ) Release notes are required, with the following suggested text:

* Fix some things. ({issue}`issuenumber`)

Fix type annotations so that mypy can check trino.client and
trino.dbapi without any type violations.

Behavioral changes:
* When called before cursor.execute():
  * iter(cursor) now raises ProgrammingError instead of
    TypeError: iter() returned non-iterator of type 'NoneType'
  * cursor.fetchone()/fetchmany()/fetchall() now raise
    ProgrammingError instead of AssertionError (TypeError with -O)
  * cursor.genall() now raises ProgrammingError instead
    of AttributeError
* TrinoRequest(max_attempts=n) with n < 1 now raises ValueError,
   instead of failing on first request with UnboundLocalError.

Fixes:
* trino.dbapi.TimeFromTicks() now works correctly, previously
  it tried to use undefined datetime.localtime
* TrinoUserError() can be formatted, previously str(error) raised
  AtttributeError
@cla-bot cla-bot Bot added the cla-signed label Sep 8, 2026
@azawlocki-sbdt
azawlocki-sbdt marked this pull request as draft September 8, 2026 15:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

1 participant