Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions newsfragments/3216.change.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove supported inline type-checking comments by teaching Ruff about runtime-evaluated ``beartype`` annotations and postponing test annotations.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ lint.flake8-tidy-imports.banned-api."operator.attrgetter".msg = "operator.attrge
lint.flake8-tidy-imports.banned-api."typing.cast".msg = """\
typing.cast is banned: use explicit type narrowing or a typed variable instead.\
"""
lint.flake8-type-checking.runtime-evaluated-decorators = [ "beartype.beartype" ]
lint.pydocstyle.convention = "google"
lint.preview = true

Expand Down
4 changes: 2 additions & 2 deletions src/vws/_async_vws_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
from beartype import BeartypeConf, beartype
from vws_auth_tools import authorization_header, rfc_1123_date

from vws.response import Response # noqa: TC001
from vws.transports import AsyncTransport # noqa: TC001
from vws.response import Response
from vws.transports import AsyncTransport


@beartype(conf=BeartypeConf(is_pep484_tower=True))
Expand Down
6 changes: 3 additions & 3 deletions src/vws/_model_targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import base64
import json
from collections.abc import Sequence # noqa: TC003
from collections.abc import Sequence
from http import HTTPStatus
from typing import Any

Expand All @@ -18,13 +18,13 @@
UnknownModelTargetDatasetError,
)
from vws.exceptions.vws_exceptions import TooManyRequestsError
from vws.model_target_datasets import ( # noqa: TC001
from vws.model_target_datasets import (
ModelTargetDatasetType,
ModelTargetModel,
ModelTargetView,
)
from vws.reports import ModelTargetDatasetStatusReport
from vws.response import Response # noqa: TC001
from vws.response import Response

OAUTH2_TOKEN_PATH = "/oauth2/token" # noqa: S105
OAUTH2_TOKEN_BODY = b"grant_type=client_credentials"
Expand Down
4 changes: 2 additions & 2 deletions src/vws/_reco_counts.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Internal helpers for the database reco counts report endpoints."""

import calendar # noqa: TC003
import calendar
import json
from http import HTTPStatus

Expand All @@ -12,7 +12,7 @@
RecoCountsReportNotReadyError,
)
from vws.reports import RecoCountsReport
from vws.response import Response # noqa: TC001
from vws.response import Response


@beartype(conf=BeartypeConf(is_pep484_tower=True))
Expand Down
4 changes: 2 additions & 2 deletions src/vws/_vws_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
from beartype import BeartypeConf, beartype
from vws_auth_tools import authorization_header, rfc_1123_date

from vws.response import Response # noqa: TC001
from vws.transports import Transport # noqa: TC001
from vws.response import Response
from vws.transports import Transport


@beartype(conf=BeartypeConf(is_pep484_tower=True))
Expand Down
2 changes: 1 addition & 1 deletion src/vws/exceptions/model_target_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from beartype import beartype

from vws.reports import ModelTargetGenerationDetail
from vws.response import Response # noqa: TC001
from vws.response import Response


@beartype
Expand Down
2 changes: 1 addition & 1 deletion src/vws/model_target_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
https://developer.vuforia.com/library/vuforia-engine/web-api/model-target-web-api/.
"""

from collections.abc import Sequence # noqa: TC003
from collections.abc import Sequence
from dataclasses import dataclass
from enum import StrEnum, unique

Expand Down
2 changes: 1 addition & 1 deletion src/vws/reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import csv
import datetime
import io
from collections.abc import Sequence # noqa: TC003
from collections.abc import Sequence
from dataclasses import dataclass
from enum import Enum, unique
from typing import Any, Self
Expand Down
12 changes: 8 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
"""Configuration, plugins and fixtures for `pytest`."""

from __future__ import annotations

import datetime
import io # noqa: TC003
from collections.abc import AsyncGenerator, Generator # noqa: TC003
from pathlib import Path # noqa: TC003
from typing import BinaryIO, Literal
from typing import TYPE_CHECKING, BinaryIO, Literal

import pytest
import pytest_asyncio
Expand All @@ -29,6 +28,11 @@
ModelTargetView,
)

if TYPE_CHECKING:
import io
from collections.abc import AsyncGenerator, Generator
from pathlib import Path

# The mock accepts one hard-coded pair of Model Target Web API OAuth2
# credentials, which it does not expose.
_MODEL_TARGET_CLIENT_ID = "client-id"
Expand Down
7 changes: 6 additions & 1 deletion tests/test_async_cloud_reco_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
AsyncCloudRecoService.
"""

import io # noqa: TC003
from __future__ import annotations

import json
import uuid
from http import HTTPStatus
from typing import TYPE_CHECKING

import pytest
from mock_vws import CloudQueryFailureResponse, MockVWS
Expand All @@ -23,6 +25,9 @@
RequestEntityTooLargeError,
)

if TYPE_CHECKING:
import io


@pytest.mark.asyncio
async def test_too_many_max_results(
Expand Down
8 changes: 6 additions & 2 deletions tests/test_async_query.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
"""Tests for the ``AsyncCloudRecoService`` querying functionality."""

import io # noqa: TC003
from __future__ import annotations

import uuid
from typing import BinaryIO
from typing import TYPE_CHECKING, BinaryIO

import pytest
from mock_vws import MockVWS
Expand All @@ -11,6 +12,9 @@
from vws import AsyncCloudRecoService, AsyncVWS
from vws.include_target_data import CloudRecoIncludeTargetData

if TYPE_CHECKING:
import io


class TestQuery:
"""Tests for making async image queries."""
Expand Down
10 changes: 7 additions & 3 deletions tests/test_async_vws.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
"""Tests for async helper functions for managing a Vuforia database."""

from __future__ import annotations

import base64
import calendar
import datetime # noqa: TC003
import io # noqa: TC003
import time
import uuid
from http import HTTPStatus
from typing import BinaryIO
from typing import TYPE_CHECKING, BinaryIO

import pytest
from mock_vws import MockVWS
Expand All @@ -33,6 +33,10 @@
from vws.response import Response
from vws.vumark_accept import VuMarkAccept

if TYPE_CHECKING:
import datetime
import io


class TestAddTarget:
"""Tests for adding a target."""
Expand Down
11 changes: 8 additions & 3 deletions tests/test_async_vws_exceptions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Tests for VWS exceptions raised from async clients."""

from __future__ import annotations

import base64
import io
import uuid
Expand All @@ -11,7 +13,6 @@
from mock_vws.states import States

from vws import AsyncVuMarkService, AsyncVWS
from vws.exceptions.base_exceptions import VWSError # noqa: TC001
from vws.exceptions.custom_exceptions import (
ServerError,
)
Expand Down Expand Up @@ -156,7 +157,9 @@ async def test_target_quota_reached(
async def test_project_state_error(
*,
state: States,
expected_exception: type[VWSError],
expected_exception: type[
ProjectSuspendedError | ProjectHasNoAPIAccessError
],
) -> None:
"""Configured project states raise their matching exceptions."""
database = CloudDatabase(state=state)
Expand Down Expand Up @@ -414,7 +417,9 @@ async def test_invalid_instance_id(
async def test_documented_vumark_error_codes(
*,
failure: VuMarkGenerationFailure,
exception_type: type[VWSError],
exception_type: type[
QuotaExceededError | LicenseCheckFailedError | AuthorizationFailedError
],
status_code: HTTPStatus,
) -> None:
"""Documented VuMark failures raise matching exceptions."""
Expand Down
7 changes: 6 additions & 1 deletion tests/test_cloud_reco_exceptions.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
"""Tests for exceptions raised when using the CloudRecoService."""

import io # noqa: TC003
from __future__ import annotations

import json
import uuid
from http import HTTPStatus
from typing import TYPE_CHECKING

import pytest
from mock_vws import CloudQueryFailureResponse, MockVWS
Expand All @@ -23,6 +25,9 @@
RequestEntityTooLargeError,
)

if TYPE_CHECKING:
import io


def test_too_many_max_results(
*,
Expand Down
8 changes: 6 additions & 2 deletions tests/test_query.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
"""Tests for the ``CloudRecoService`` querying functionality."""

from __future__ import annotations

import datetime
import io # noqa: TC003
import json
import secrets
import uuid
from http import HTTPStatus
from typing import BinaryIO
from typing import TYPE_CHECKING, BinaryIO

import pytest
import requests
Expand All @@ -18,6 +19,9 @@
from vws.include_target_data import CloudRecoIncludeTargetData
from vws.response import Response

if TYPE_CHECKING:
import io


class _JSONResponseTransport:
"""A transport which returns one JSON response body."""
Expand Down
7 changes: 6 additions & 1 deletion tests/test_transports.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
"""Tests for HTTP transport implementations."""

import io # noqa: TC003
from __future__ import annotations

import uuid
from http import HTTPStatus
from typing import TYPE_CHECKING

import httpx
import httpx2
Expand Down Expand Up @@ -36,6 +38,9 @@
)
from vws.vumark_accept import VuMarkAccept

if TYPE_CHECKING:
import io


class TestHTTPXTransport:
"""Tests for ``HTTPXTransport``."""
Expand Down
8 changes: 6 additions & 2 deletions tests/test_vws.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
"""Tests for helper functions for managing a Vuforia database."""

from __future__ import annotations

import base64
import calendar
import datetime
import io # noqa: TC003
import json
import secrets
import time
import uuid
from http import HTTPStatus
from typing import BinaryIO
from typing import TYPE_CHECKING, BinaryIO

import pytest
import requests
Expand Down Expand Up @@ -40,6 +41,9 @@
from vws.response import Response
from vws.vumark_accept import VuMarkAccept

if TYPE_CHECKING:
import io


class _JSONResponseTransport:
"""A transport which returns one JSON response body."""
Expand Down