Skip to content

Commit

Permalink
Fix typing errors
Browse files Browse the repository at this point in the history
Pyright can't infer that lookup_package_info returns a Page if `page`
and `size` are passed in, and returns a Sequence otherwise.
Using an isinstance check instead of checking `page` and `size` gets us
partway, however the generic type information for Page[T] is lost within
this type guard, so we must still ignore type checking a bit to prevent
"varaiable is of unknown type" errors.
  • Loading branch information
Robin5605 committed Oct 11, 2024
1 parent f6e6593 commit 934d886
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions tests/test_package.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Optional
import datetime

from fastapi_pagination import Page
import pytest
from fastapi import HTTPException
from letsbuilda.pypi import PyPIServices
Expand Down Expand Up @@ -59,9 +60,10 @@ def test_package_lookup(
}

actual_scans = lookup_package_info(db_session, since, name, version, page, size)
actual_scan_set = (
{(scan.name, scan.version) for scan in actual_scans.items}
if page and size

actual_scan_set: set[tuple[str, str | None]] = (
{(scan.name, scan.version) for scan in actual_scans.items} # type: ignore
if isinstance(actual_scans, Page)
else {(scan.name, scan.version) for scan in actual_scans}
)

Expand Down

0 comments on commit 934d886

Please sign in to comment.