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
2 changes: 1 addition & 1 deletion conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def fixture_make_image_file(
"""
new_image = Path("high_quality_image.jpg")
buffer = high_quality_image.getvalue()
new_image.write_bytes(data=buffer)
_ = new_image.write_bytes(data=buffer)
yield
new_image.unlink()

Expand Down
4 changes: 2 additions & 2 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ The report is generated in the background, and the URL it is served from expires
}

# This database has no targets, so nothing has been recognized.
assert not reco_counts_by_target_id
assert reco_counts_by_target_id == {}

Model Targets
-------------
Expand Down Expand Up @@ -218,7 +218,7 @@ Transports are available for `requests`_, `httpx`_ and `HTTPX2`_.
)

# This database has no targets.
assert not vws_client.list_targets()
assert len(vws_client.list_targets()) == 0

.. _requests: https://pypi.org/project/requests/
.. _httpx: https://pypi.org/project/httpx/
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ plugins = [

[tool.pyrefly]
errors.non-exhaustive-match = "error"
preset = "strict"
preset = "all"

[tool.pyright]
typeCheckingMode = "strict"
Expand Down
1 change: 1 addition & 0 deletions spelling_private_dict.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ plugins
png
pragma
py
pyrefly
pyright
pytest
readme
Expand Down
4 changes: 2 additions & 2 deletions src/vws/_image_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
def get_image_data(image: ImageType) -> bytes:
"""Get the data of an image file."""
original_tell = image.tell()
image.seek(0)
_ = image.seek(0)
image_data = image.read()
image.seek(original_tell)
_ = image.seek(original_tell)
return image_data
8 changes: 4 additions & 4 deletions src/vws/_model_targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def dataset_download_path(


@beartype(conf=BeartypeConf(is_pep484_tower=True))
def _view_dict(*, view: ModelTargetView) -> dict[str, Any]:
def _view_dict(*, view: ModelTargetView) -> dict[str, Any]: # pyrefly: ignore [explicit-any]
"""Get the request representation of a guide view.

Args:
Expand All @@ -171,7 +171,7 @@ def _view_dict(*, view: ModelTargetView) -> dict[str, Any]:
Returns:
The guide view, as it is sent to Vuforia.
"""
view_dict: dict[str, Any] = {
view_dict: dict[str, Any] = { # pyrefly: ignore [explicit-any]
"name": view.name,
"guideViewPosition": {
"rotation": list(view.guide_view_position.rotation),
Expand All @@ -185,7 +185,7 @@ def _view_dict(*, view: ModelTargetView) -> dict[str, Any]:


@beartype(conf=BeartypeConf(is_pep484_tower=True))
def _model_dict(*, model: ModelTargetModel) -> dict[str, Any]:
def _model_dict(*, model: ModelTargetModel) -> dict[str, Any]: # pyrefly: ignore [explicit-any]
"""Get the request representation of a model.

Args:
Expand All @@ -194,7 +194,7 @@ def _model_dict(*, model: ModelTargetModel) -> dict[str, Any]:
Returns:
The model, as it is sent to Vuforia.
"""
model_dict: dict[str, Any] = {"name": model.name}
model_dict: dict[str, Any] = {"name": model.name} # pyrefly: ignore [explicit-any]
optional_values: dict[str, str | None] = {
"automaticColoring": model.automatic_coloring,
"cadDataBlob": model.cad_data_blob,
Expand Down
3 changes: 2 additions & 1 deletion src/vws/async_model_target_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,10 @@ async def make_request(
Vuforia is rate limiting access.
"""
access_token = await self.get_access_token()
request_headers = extra_headers if extra_headers is not None else {}
headers = {
"Authorization": f"Bearer {access_token}",
**(extra_headers or {}),
**request_headers,
}

response = await self._transport(
Expand Down
10 changes: 5 additions & 5 deletions src/vws/async_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,15 @@ async def query(
targets.
"""
image_content = _get_image_data(image=image)
body: dict[str, Any] = {
body: dict[str, Any] = { # pyrefly: ignore [explicit-any]
"image": (
"image.jpeg",
image_content,
"image/jpeg",
),
"max_num_results": (
None,
int(max_num_results),
max_num_results,
"text/plain",
),
"include_target_data": (
Expand Down Expand Up @@ -207,7 +207,7 @@ async def query(
raise CloudRecoError(response=response) from exc
raise

result_code = response_body["result_code"]
result_code = response_body["result_code"] # pyrefly: ignore [unknown-variable-type]
if result_code != "Success":
exception = {
"AuthenticationFailure": (AuthenticationFailureError),
Expand All @@ -217,8 +217,8 @@ async def query(
}[result_code]
raise exception(response=response)

result_list = list(response_body["results"])
result_list = list(response_body["results"]) # pyrefly: ignore [unknown-argument-type]
return [
QueryResult.from_response_dict(response_dict=item)
QueryResult.from_response_dict(response_dict=item) # pyrefly: ignore [unknown-argument-type]
for item in result_list
]
5 changes: 2 additions & 3 deletions src/vws/async_vumark_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,8 @@ async def generate_vumark_instance(
if response.status_code == HTTPStatus.OK:
return response.content

result_code = json.loads(s=response.text)["result_code"]

result_code = json.loads(s=response.text)["result_code"] # pyrefly: ignore [unknown-variable-type]
raise VWSError.from_result_code(
result_code=result_code,
result_code=result_code, # pyrefly: ignore [unknown-argument-type]
response=response,
)
13 changes: 6 additions & 7 deletions src/vws/async_vws.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ async def make_request(
request_path=request_path,
base_vws_url=self._base_vws_url,
request_timeout_seconds=self._request_timeout_seconds,
extra_headers=extra_headers or {},
extra_headers=(extra_headers if extra_headers is not None else {}),
transport=self._transport,
)

Expand All @@ -152,13 +152,12 @@ async def make_request(
): # pragma: no cover
raise ServerError(response=response)

result_code = json.loads(s=response.text)["result_code"]

result_code = json.loads(s=response.text)["result_code"] # pyrefly: ignore [unknown-variable-type]
if result_code == expected_result_code:
return response

raise VWSError.from_result_code(
result_code=result_code,
result_code=result_code, # pyrefly: ignore [unknown-argument-type]
response=response,
)

Expand Down Expand Up @@ -239,7 +238,7 @@ async def add_target(
content_type="application/json",
)

return str(object=json.loads(s=response.text)["target_id"])
return str(object=json.loads(s=response.text)["target_id"]) # pyrefly: ignore [unknown-argument-type]

async def get_target_record(self, target_id: str) -> TargetStatusAndRecord:
"""Get a given target's target record from the Target
Expand Down Expand Up @@ -374,7 +373,7 @@ async def list_targets(self) -> list[str]:
content_type="application/json",
)

return list(json.loads(s=response.text)["results"])
return list(json.loads(s=response.text)["results"]) # pyrefly: ignore [unknown-argument-type]

async def get_target_summary_report(
self, target_id: str
Expand Down Expand Up @@ -659,7 +658,7 @@ async def get_duplicate_targets(self, target_id: str) -> list[str]:
)

return list(
json.loads(s=response.text)["similar_targets"],
json.loads(s=response.text)["similar_targets"], # pyrefly: ignore [unknown-argument-type]
)

async def update_target(
Expand Down
15 changes: 8 additions & 7 deletions src/vws/exceptions/model_target_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def _is_json_object(*, value: object) -> bool:


@beartype
def _json_object(*, value: str) -> dict[str, Any]:
def _json_object(*, value: str) -> dict[str, Any]: # pyrefly: ignore [explicit-any]
"""Get a JSON object from a string.

Args:
Expand All @@ -38,19 +38,19 @@ def _json_object(*, value: str) -> dict[str, Any]:
JSON object.
"""
try:
loaded: Any = json.loads(s=value)
loaded: Any = json.loads(s=value) # pyrefly: ignore [explicit-any]
except json.JSONDecodeError:
return {}

if not _is_json_object(value=loaded):
return {}

json_object: dict[str, Any] = loaded
json_object: dict[str, Any] = loaded # pyrefly: ignore [explicit-any]
return json_object


@beartype
def _error_dict(*, response: Response) -> dict[str, Any]:
def _error_dict(*, response: Response) -> dict[str, Any]: # pyrefly: ignore [explicit-any]
"""Get the error object of a Model Target Web API error response.

Args:
Expand All @@ -66,11 +66,11 @@ def _error_dict(*, response: Response) -> dict[str, Any]:
if "error" not in body:
return {}

error: Any = body["error"]
error: Any = body["error"] # pyrefly: ignore [explicit-any]
if not _is_json_object(value=error):
return {}

error_dict: dict[str, Any] = error
error_dict: dict[str, Any] = error # pyrefly: ignore [explicit-any]
return error_dict


Expand Down Expand Up @@ -122,7 +122,8 @@ def details(self) -> list[ModelTargetGenerationDetail]:

return [
ModelTargetGenerationDetail(
code=detail["code"],
code=detail["code"], # pyrefly: ignore [unknown-argument-type]
# pyrefly: ignore [unknown-argument-type]
message=detail["message"],
)
for detail in error["details"]
Expand Down
9 changes: 6 additions & 3 deletions src/vws/exceptions/vws_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def _target_id_from_url(*, url: str) -> str:
path segment after ``targets``, ``summary``, or ``duplicates``.
"""
path = urlparse(url=url).path
parts = [part for part in path.split(sep="/") if part]
parts = [part for part in path.split(sep="/") if bool(part)]
for marker in ("targets", "summary", "duplicates"):
try:
marker_index = parts.index(marker)
Expand Down Expand Up @@ -143,9 +143,12 @@ class TargetNameExistError(VWSError):
@property
def target_name(self) -> str:
"""The target name which already exists."""
response_body = self.response.request_body or b""
response_body = self.response.request_body
if not isinstance(response_body, str | bytes): # pragma: no cover
msg = "A target-name error response must have a request body."
raise TypeError(msg)
request_json = json.loads(s=response_body)
return str(object=request_json["name"])
return str(object=request_json["name"]) # pyrefly: ignore [unknown-argument-type]


@beartype
Expand Down
5 changes: 3 additions & 2 deletions src/vws/model_target_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,10 @@ def make_request(
~vws.exceptions.vws_exceptions.TooManyRequestsError:
Vuforia is rate limiting access.
"""
request_headers = extra_headers if extra_headers is not None else {}
headers = {
"Authorization": f"Bearer {self.get_access_token()}",
**(extra_headers or {}),
**request_headers,
}

response = self._transport(
Expand Down Expand Up @@ -356,7 +357,7 @@ def delete_dataset(
~vws.exceptions.model_target_exceptions.ModelTargetOAuth2Error:
Vuforia did not give an access token.
"""
self.make_request(
_ = self.make_request(
method=HTTPMethod.DELETE,
data=b"",
request_path=dataset_path(
Expand Down
10 changes: 5 additions & 5 deletions src/vws/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ def query(
An ordered list of target details of matching targets.
"""
image_content = _get_image_data(image=image)
body: dict[str, Any] = {
body: dict[str, Any] = { # pyrefly: ignore [explicit-any]
"image": ("image.jpeg", image_content, "image/jpeg"),
"max_num_results": (None, int(max_num_results), "text/plain"),
"max_num_results": (None, max_num_results, "text/plain"),
"include_target_data": (
None,
include_target_data.value,
Expand Down Expand Up @@ -177,7 +177,7 @@ def query(
raise CloudRecoError(response=response) from exc
raise

result_code = response_body["result_code"]
result_code = response_body["result_code"] # pyrefly: ignore [unknown-variable-type]
if result_code != "Success":
exception = {
"AuthenticationFailure": AuthenticationFailureError,
Expand All @@ -187,8 +187,8 @@ def query(
}[result_code]
raise exception(response=response)

result_list = list(response_body["results"])
result_list = list(response_body["results"]) # pyrefly: ignore [unknown-argument-type]
return [
QueryResult.from_response_dict(response_dict=item)
QueryResult.from_response_dict(response_dict=item) # pyrefly: ignore [unknown-argument-type]
for item in result_list
]
Loading