Skip to content

Bump pyright from 1.1.304 to 1.1.308 #1591

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 15, 2023
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
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ module = [
"cv2",
"docker",
"docker.errors",
"docker.models.containers",
"docker.models.networks",
"multipart",
"sybil",
Expand Down Expand Up @@ -211,6 +212,7 @@ ignore = [
# Ignore "too-many-*" errors as they seem to get in the way more than
# helping.
"PLR0913",
"PLR0915",
# Allow 'assert' in tests as it is the standard for pytest.
# Also, allow 'assert' in other code as it is the standard for Python type hint
# narrowing - see
Expand Down Expand Up @@ -294,7 +296,7 @@ dev = [
"pydocstyle==6.3.0",
"pyenchant==3.2.2",
"pylint==2.17.4",
"pyright==1.1.304",
"pyright==1.1.308",
"pyroma==4.2",
"pytest-cov==4.0.0",
"pytest==7.3.1",
Expand Down
1 change: 1 addition & 0 deletions spelling_private_dict.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ recognitions
refactoring
regex
reimplementation
reportGeneralTypeIssues
repr
reqheader
reqjson
Expand Down
4 changes: 3 additions & 1 deletion src/mock_vws/_query_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ def get_query_match_response_text(
else:
include_target_data = parsed_include_target_data.value.lower()

image_value = parsed.get("image").raw
image_part = parsed.get("image")
assert image_part is not None
image_value = image_part.raw
gmt = ZoneInfo("GMT")
now = datetime.datetime.now(tz=gmt)

Expand Down
24 changes: 16 additions & 8 deletions src/mock_vws/_query_validators/image_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ def validate_image_file_size(
boundary = email_message.get_boundary()
assert isinstance(boundary, str)
parsed = multipart.MultipartParser(stream=body_file, boundary=boundary)
image = parsed.get("image").raw
image_part = parsed.get("image")
assert image_part is not None
image_value = image_part.raw

# This is the documented maximum size of a PNG as per.
# https://library.vuforia.com/web-api/vuforia-query-web-api.
Expand All @@ -77,7 +79,7 @@ def validate_image_file_size(
# Ignore coverage on this as there is a bug in urllib3 which means that we
# do not trigger this exception.
# See https://github.com/urllib3/urllib3/issues/2733.
if len(image) > max_bytes: # pragma: no cover
if len(image_value) > max_bytes: # pragma: no cover
_LOGGER.warning(msg="The image file size is too large.")
raise RequestEntityTooLarge

Expand All @@ -104,8 +106,10 @@ def validate_image_dimensions(
boundary = email_message.get_boundary()
assert isinstance(boundary, str)
parsed = multipart.MultipartParser(stream=body_file, boundary=boundary)
image = parsed.get("image").raw
image_file = io.BytesIO(image)
image_part = parsed.get("image")
assert image_part is not None
image_value = image_part.raw
image_file = io.BytesIO(image_value)
pil_image = Image.open(image_file)
max_width = 30000
max_height = 30000
Expand Down Expand Up @@ -137,9 +141,11 @@ def validate_image_format(
boundary = email_message.get_boundary()
assert isinstance(boundary, str)
parsed = multipart.MultipartParser(stream=body_file, boundary=boundary)
image = parsed.get("image").raw
image_part = parsed.get("image")
assert image_part is not None
image_value = image_part.raw

image_file = io.BytesIO(image)
image_file = io.BytesIO(image_value)
pil_image = Image.open(image_file)

if pil_image.format in {"PNG", "JPEG"}:
Expand Down Expand Up @@ -170,9 +176,11 @@ def validate_image_is_image(
boundary = email_message.get_boundary()
assert isinstance(boundary, str)
parsed = multipart.MultipartParser(stream=body_file, boundary=boundary)
image = parsed.get("image").raw
image_part = parsed.get("image")
assert image_part is not None
image_value = image_part.raw

image_file = io.BytesIO(image)
image_file = io.BytesIO(image_value)

try:
Image.open(image_file)
Expand Down
8 changes: 7 additions & 1 deletion src/mock_vws/target_raters.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
import numpy as np
from PIL import Image

# cv2 errors cannot be inferred without type stubs.
# See https://github.com/opencv/opencv/issues/14590.
_CV2_ERROR = (
cv2.error # pyright: ignore[reportGeneralTypeIssues] # noqa: E501 # pylint: disable=no-member
)


@functools.cache
def _get_brisque_target_tracking_rating(image_content: bytes) -> int:
Expand All @@ -32,7 +38,7 @@ def _get_brisque_target_tracking_rating(image_content: bytes) -> int:
with np.errstate(divide="ignore", invalid="ignore"):
try:
score = brisque_obj.score(img=image_array)
except (cv2.error, ValueError): # pylint: disable=no-member
except (_CV2_ERROR, ValueError):
return 0
if math.isnan(score):
return 0
Expand Down
32 changes: 25 additions & 7 deletions tests/mock_vws/test_docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@
import docker
import pytest
import requests
from docker.errors import BuildError
from docker.errors import BuildError, NotFound
from docker.models.containers import Container
from docker.models.networks import Network
from mock_vws.database import VuforiaDatabase
from vws import VWS, CloudRecoService

if TYPE_CHECKING:
import io
from collections.abc import Iterator

from docker.models.networks import Network


# We do not cover this function because hitting particular branches depends on
# timing.
Expand Down Expand Up @@ -72,13 +72,15 @@ def fixture_custom_bridge_network() -> Iterator[Network]:
name="test-vws-bridge-" + uuid.uuid4().hex,
driver="bridge",
)
except docker.errors.NotFound:
except NotFound:
# On Windows the "bridge" network driver is not available and we use
# the "nat" driver instead.
network = client.networks.create(
name="test-vws-bridge-" + uuid.uuid4().hex,
driver="nat",
)

assert isinstance(network, Network)
try:
yield network
finally:
Expand Down Expand Up @@ -115,7 +117,7 @@ def test_build_and_run(
vwq_tag = f"vws-mock-vwq:latest-{random}"

try:
target_manager_image, _ = client.images.build(
target_manager_build_result = client.images.build(
path=str(repository_root),
dockerfile=str(target_manager_dockerfile),
tag=target_manager_tag,
Expand All @@ -133,16 +135,23 @@ def test_build_and_run(
reason = "We do not currently support using Windows containers."
pytest.skip(reason)

vws_image, _ = client.images.build(
assert isinstance(target_manager_build_result, tuple)
target_manager_image, _ = target_manager_build_result

vws_build_result = client.images.build(
path=str(repository_root),
dockerfile=str(vws_dockerfile),
tag=vws_tag,
)
vwq_image, _ = client.images.build(
assert isinstance(vws_build_result, tuple)
vws_image, _ = vws_build_result
vwq_build_result = client.images.build(
path=str(repository_root),
dockerfile=str(vwq_dockerfile),
tag=vwq_tag,
)
assert isinstance(vwq_build_result, tuple)
vwq_image, _ = vwq_build_result

database = VuforiaDatabase()
target_manager_container_name = "vws-mock-target-manager-" + random
Expand Down Expand Up @@ -178,9 +187,16 @@ def test_build_and_run(
},
)

assert isinstance(target_manager_container, Container)
assert isinstance(vws_container, Container)
assert isinstance(vwq_container, Container)
for container in (target_manager_container, vws_container, vwq_container):
container.reload()

assert isinstance(target_manager_container.attrs, dict)
target_manager_port_attrs = target_manager_container.attrs[
"NetworkSettings"
]["Ports"]
target_manager_port_attrs = target_manager_container.attrs[
"NetworkSettings"
]["Ports"]
Expand All @@ -189,10 +205,12 @@ def test_build_and_run(
"HostPort"
]

assert isinstance(vws_container.attrs, dict)
vws_port_attrs = vws_container.attrs["NetworkSettings"]["Ports"]
vws_host_ip = vws_port_attrs["5000/tcp"][0]["HostIp"]
vws_host_port = vws_port_attrs["5000/tcp"][0]["HostPort"]

assert isinstance(vwq_container.attrs, dict)
vwq_port_attrs = vwq_container.attrs["NetworkSettings"]["Ports"]
vwq_host_ip = vwq_port_attrs["5000/tcp"][0]["HostIp"]
vwq_host_port = vwq_port_attrs["5000/tcp"][0]["HostPort"]
Expand Down