Skip to content

Commit 253a1da

Browse files
Merge pull request #1591 from VWS-Python/dependabot/pip/pyright-1.1.308
Bump pyright from 1.1.304 to 1.1.308
2 parents e1c2bdd + e41290b commit 253a1da

File tree

6 files changed

+55
-18
lines changed

6 files changed

+55
-18
lines changed

pyproject.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ module = [
144144
"cv2",
145145
"docker",
146146
"docker.errors",
147+
"docker.models.containers",
147148
"docker.models.networks",
148149
"multipart",
149150
"sybil",
@@ -211,6 +212,7 @@ ignore = [
211212
# Ignore "too-many-*" errors as they seem to get in the way more than
212213
# helping.
213214
"PLR0913",
215+
"PLR0915",
214216
# Allow 'assert' in tests as it is the standard for pytest.
215217
# Also, allow 'assert' in other code as it is the standard for Python type hint
216218
# narrowing - see
@@ -294,7 +296,7 @@ dev = [
294296
"pydocstyle==6.3.0",
295297
"pyenchant==3.2.2",
296298
"pylint==2.17.4",
297-
"pyright==1.1.304",
299+
"pyright==1.1.308",
298300
"pyroma==4.2",
299301
"pytest-cov==4.0.0",
300302
"pytest==7.3.1",

spelling_private_dict.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ recognitions
8080
refactoring
8181
regex
8282
reimplementation
83+
reportGeneralTypeIssues
8384
repr
8485
reqheader
8586
reqjson

src/mock_vws/_query_tools.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ def get_query_match_response_text(
8484
else:
8585
include_target_data = parsed_include_target_data.value.lower()
8686

87-
image_value = parsed.get("image").raw
87+
image_part = parsed.get("image")
88+
assert image_part is not None
89+
image_value = image_part.raw
8890
gmt = ZoneInfo("GMT")
8991
now = datetime.datetime.now(tz=gmt)
9092

src/mock_vws/_query_validators/image_validators.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ def validate_image_file_size(
6767
boundary = email_message.get_boundary()
6868
assert isinstance(boundary, str)
6969
parsed = multipart.MultipartParser(stream=body_file, boundary=boundary)
70-
image = parsed.get("image").raw
70+
image_part = parsed.get("image")
71+
assert image_part is not None
72+
image_value = image_part.raw
7173

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

@@ -104,8 +106,10 @@ def validate_image_dimensions(
104106
boundary = email_message.get_boundary()
105107
assert isinstance(boundary, str)
106108
parsed = multipart.MultipartParser(stream=body_file, boundary=boundary)
107-
image = parsed.get("image").raw
108-
image_file = io.BytesIO(image)
109+
image_part = parsed.get("image")
110+
assert image_part is not None
111+
image_value = image_part.raw
112+
image_file = io.BytesIO(image_value)
109113
pil_image = Image.open(image_file)
110114
max_width = 30000
111115
max_height = 30000
@@ -137,9 +141,11 @@ def validate_image_format(
137141
boundary = email_message.get_boundary()
138142
assert isinstance(boundary, str)
139143
parsed = multipart.MultipartParser(stream=body_file, boundary=boundary)
140-
image = parsed.get("image").raw
144+
image_part = parsed.get("image")
145+
assert image_part is not None
146+
image_value = image_part.raw
141147

142-
image_file = io.BytesIO(image)
148+
image_file = io.BytesIO(image_value)
143149
pil_image = Image.open(image_file)
144150

145151
if pil_image.format in {"PNG", "JPEG"}:
@@ -170,9 +176,11 @@ def validate_image_is_image(
170176
boundary = email_message.get_boundary()
171177
assert isinstance(boundary, str)
172178
parsed = multipart.MultipartParser(stream=body_file, boundary=boundary)
173-
image = parsed.get("image").raw
179+
image_part = parsed.get("image")
180+
assert image_part is not None
181+
image_value = image_part.raw
174182

175-
image_file = io.BytesIO(image)
183+
image_file = io.BytesIO(image_value)
176184

177185
try:
178186
Image.open(image_file)

src/mock_vws/target_raters.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111
import numpy as np
1212
from PIL import Image
1313

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

1521
@functools.cache
1622
def _get_brisque_target_tracking_rating(image_content: bytes) -> int:
@@ -32,7 +38,7 @@ def _get_brisque_target_tracking_rating(image_content: bytes) -> int:
3238
with np.errstate(divide="ignore", invalid="ignore"):
3339
try:
3440
score = brisque_obj.score(img=image_array)
35-
except (cv2.error, ValueError): # pylint: disable=no-member
41+
except (_CV2_ERROR, ValueError):
3642
return 0
3743
if math.isnan(score):
3844
return 0

tests/mock_vws/test_docker.py

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@
1313
import docker
1414
import pytest
1515
import requests
16-
from docker.errors import BuildError
16+
from docker.errors import BuildError, NotFound
17+
from docker.models.containers import Container
18+
from docker.models.networks import Network
1719
from mock_vws.database import VuforiaDatabase
1820
from vws import VWS, CloudRecoService
1921

2022
if TYPE_CHECKING:
2123
import io
2224
from collections.abc import Iterator
2325

24-
from docker.models.networks import Network
25-
2626

2727
# We do not cover this function because hitting particular branches depends on
2828
# timing.
@@ -72,13 +72,15 @@ def fixture_custom_bridge_network() -> Iterator[Network]:
7272
name="test-vws-bridge-" + uuid.uuid4().hex,
7373
driver="bridge",
7474
)
75-
except docker.errors.NotFound:
75+
except NotFound:
7676
# On Windows the "bridge" network driver is not available and we use
7777
# the "nat" driver instead.
7878
network = client.networks.create(
7979
name="test-vws-bridge-" + uuid.uuid4().hex,
8080
driver="nat",
8181
)
82+
83+
assert isinstance(network, Network)
8284
try:
8385
yield network
8486
finally:
@@ -115,7 +117,7 @@ def test_build_and_run(
115117
vwq_tag = f"vws-mock-vwq:latest-{random}"
116118

117119
try:
118-
target_manager_image, _ = client.images.build(
120+
target_manager_build_result = client.images.build(
119121
path=str(repository_root),
120122
dockerfile=str(target_manager_dockerfile),
121123
tag=target_manager_tag,
@@ -133,16 +135,23 @@ def test_build_and_run(
133135
reason = "We do not currently support using Windows containers."
134136
pytest.skip(reason)
135137

136-
vws_image, _ = client.images.build(
138+
assert isinstance(target_manager_build_result, tuple)
139+
target_manager_image, _ = target_manager_build_result
140+
141+
vws_build_result = client.images.build(
137142
path=str(repository_root),
138143
dockerfile=str(vws_dockerfile),
139144
tag=vws_tag,
140145
)
141-
vwq_image, _ = client.images.build(
146+
assert isinstance(vws_build_result, tuple)
147+
vws_image, _ = vws_build_result
148+
vwq_build_result = client.images.build(
142149
path=str(repository_root),
143150
dockerfile=str(vwq_dockerfile),
144151
tag=vwq_tag,
145152
)
153+
assert isinstance(vwq_build_result, tuple)
154+
vwq_image, _ = vwq_build_result
146155

147156
database = VuforiaDatabase()
148157
target_manager_container_name = "vws-mock-target-manager-" + random
@@ -178,9 +187,16 @@ def test_build_and_run(
178187
},
179188
)
180189

190+
assert isinstance(target_manager_container, Container)
191+
assert isinstance(vws_container, Container)
192+
assert isinstance(vwq_container, Container)
181193
for container in (target_manager_container, vws_container, vwq_container):
182194
container.reload()
183195

196+
assert isinstance(target_manager_container.attrs, dict)
197+
target_manager_port_attrs = target_manager_container.attrs[
198+
"NetworkSettings"
199+
]["Ports"]
184200
target_manager_port_attrs = target_manager_container.attrs[
185201
"NetworkSettings"
186202
]["Ports"]
@@ -189,10 +205,12 @@ def test_build_and_run(
189205
"HostPort"
190206
]
191207

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

213+
assert isinstance(vwq_container.attrs, dict)
196214
vwq_port_attrs = vwq_container.attrs["NetworkSettings"]["Ports"]
197215
vwq_host_ip = vwq_port_attrs["5000/tcp"][0]["HostIp"]
198216
vwq_host_port = vwq_port_attrs["5000/tcp"][0]["HostPort"]

0 commit comments

Comments
 (0)