From 934d886c3899ad10e4f85b6167a69e90ca397ea9 Mon Sep 17 00:00:00 2001 From: Robin5605 Date: Fri, 11 Oct 2024 00:27:13 -0500 Subject: [PATCH] Fix typing errors 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. --- tests/test_package.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/test_package.py b/tests/test_package.py index ba18a3d..76e8388 100644 --- a/tests/test_package.py +++ b/tests/test_package.py @@ -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 @@ -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} )