Skip to content

Commit dcce0e4

Browse files
Merge pull request #3580 from VWS-Python/strictest-ty-config
Use Ty's strictest recommended configuration
2 parents aab4a17 + ff4b336 commit dcce0e4

11 files changed

Lines changed: 38 additions & 17 deletions

File tree

pyproject.toml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ line-length = 79
158158
lint.select = [
159159
"ALL",
160160
]
161+
lint.extend-select = [ "ANN", "PGH003", "PYI" ]
161162
lint.ignore = [
162163
# Ruff warns that this conflicts with the formatter.
163164
"COM812",
@@ -180,6 +181,7 @@ lint.ignore = [
180181
"TC002",
181182
"TC003",
182183
]
184+
lint.explicit-preview-rules = true
183185
lint.per-file-ignores."doccmd_*.py" = [
184186
# Allow our chosen docstring line-style - pydocstringformatter handles
185187
# formatting but docstrings in docs may not match this style.
@@ -205,6 +207,7 @@ lint.flake8-tidy-imports.banned-api."typing.cast".msg = """\
205207
typing.cast is banned: use explicit type narrowing or a typed variable instead.\
206208
"""
207209
lint.pydocstyle.convention = "google"
210+
lint.preview = true
208211

209212
[tool.pylint]
210213
# Disable the message, report, category or checker with the given id(s). You
@@ -456,6 +459,23 @@ typeCheckingMode = "strict"
456459
enableTypeIgnoreComments = false
457460
reportUnnecessaryTypeIgnoreComment = true
458461

462+
[tool.ty]
463+
rules.blanket-ignore-comment = "error"
464+
rules.division-by-zero = "warn"
465+
rules.dynamic-function-decorator-return = "error"
466+
rules.missing-type-argument = "error"
467+
rules.possibly-missing-attribute = "warn"
468+
rules.possibly-missing-import = "warn"
469+
rules.possibly-unresolved-reference = "warn"
470+
rules.unsound-assignment = "error"
471+
rules.unsound-return-statement = "error"
472+
rules.unsound-yield = "error"
473+
rules.unsupported-dynamic-base = "warn"
474+
terminal.error-on-warning = true
475+
analysis.respect-type-ignore-comments = false
476+
analysis.strict-equality-semantics = true
477+
analysis.strict-generic-narrowing = true
478+
459479
[tool.pytest]
460480
addopts = [
461481
"--strict-markers",

spelling_private_dict.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ timestamp
129129
todo
130130
travis
131131
txt
132+
ty
132133
unlinks
133134
unmocked
134135
unrouted

src/mock_vws/_httpx2_mock_server/decorators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ def _mock_routes(
288288
handler: _Handler = getattr( # pylint: disable=bad-builtin
289289
api,
290290
route.route_name,
291-
)
291+
) # ty: ignore[unsound-assignment]
292292
httpx2_handler = delayed_httpx2_handler(
293293
handler=_httpx2_handler(handler=handler, base_path=base_path),
294294
delay_seconds=response_delay_seconds,

src/mock_vws/_model_target_web_api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,8 @@ def _jwt_scopes(*, bearer_token: str) -> frozenset[str]:
345345
)
346346
scope = payload.get("scope", "") # pyrefly: ignore [unknown-variable-type]
347347
if not isinstance(scope, str):
348-
return frozenset()
349-
return frozenset(scope.split())
348+
return frozenset() # ty: ignore[unsound-return-statement]
349+
return frozenset(scope.split()) # ty: ignore[unsound-return-statement]
350350

351351

352352
@beartype

src/mock_vws/_services_validators/name_validators.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def _given_name(*, context: ValidatorContext) -> str | None:
3333
:py:func:`validate_name_type`.
3434
"""
3535
request_json = context.request_json
36-
name: str | None = request_json.get("name")
36+
name: str | None = request_json.get("name") # ty: ignore[unsound-assignment]
3737
return name
3838

3939

@@ -63,7 +63,7 @@ def _new_target_name(*, context: ValidatorContext) -> str:
6363
a request which does not give one, and :py:func:`validate_name_type`
6464
has already rejected one which is not a string.
6565
"""
66-
name: str = context.request_json["name"]
66+
name: str = context.request_json["name"] # ty: ignore[unsound-assignment]
6767
return name
6868

6969

tests/conftest.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ def endpoint(*, request: pytest.FixtureRequest) -> Endpoint:
206206
the cross-cutting ``Authorization`` and ``Date`` header concerns do not
207207
apply to it.
208208
"""
209-
endpoint_fixture: Endpoint = request.getfixturevalue(argname=request.param)
209+
endpoint_fixture: Endpoint = request.getfixturevalue(argname=request.param) # ty: ignore[unsound-assignment]
210210
return endpoint_fixture
211211

212212

@@ -234,7 +234,7 @@ def model_target_endpoint(
234234
"""
235235
endpoint_fixture: ModelTargetEndpoint = request.getfixturevalue(
236236
argname=request.param,
237-
)
237+
) # ty: ignore[unsound-assignment]
238238
return endpoint_fixture
239239

240240

@@ -265,7 +265,7 @@ def not_base64_encoded_processable(*, request: pytest.FixtureRequest) -> str:
265265
266266
``UNPROCESSABLE_ENTITY`` when this is given.
267267
"""
268-
not_base64_encoded_string: str = request.param
268+
not_base64_encoded_string: str = request.param # ty: ignore[unsound-assignment]
269269

270270
with pytest.raises(expected_exception=binascii.Error):
271271
_ = base64.b64decode(s=not_base64_encoded_string, validate=True)
@@ -291,7 +291,7 @@ def not_base64_encoded_not_processable(
291291
will
292292
return an ``UNPROCESSABLE_ENTITY`` response when this is given.
293293
"""
294-
not_base64_encoded_string: str = request.param
294+
not_base64_encoded_string: str = request.param # ty: ignore[unsound-assignment]
295295

296296
with pytest.raises(expected_exception=binascii.Error):
297297
_ = base64.b64decode(s=not_base64_encoded_string, validate=True)

tests/mock_vws/test_docker.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,13 +252,13 @@ def fixture_custom_bridge_network() -> Iterator[Network]:
252252
yield network
253253
finally:
254254
network.reload()
255-
images_to_remove: Iterable[Image] = set()
255+
images_to_remove: Iterable[Image] = set() # ty: ignore[unsound-assignment]
256256
for container in network.containers:
257257
network.disconnect(container=container)
258258
container.stop()
259259
container.remove(v=True, force=True)
260260
assert container.image is not None
261-
images_to_remove = {*images_to_remove, container.image}
261+
images_to_remove = {*images_to_remove, container.image} # ty: ignore[unsound-assignment]
262262

263263
# This does leave behind untagged images.
264264
for image in images_to_remove:

tests/mock_vws/test_healthcheck.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def _unused_port() -> int:
4242
"""Return a port with nothing listening on it."""
4343
with socket.socket() as sock:
4444
sock.bind(("localhost", 0))
45-
port: int = sock.getsockname()[1]
45+
port: int = sock.getsockname()[1] # ty: ignore[unsound-assignment]
4646
return port
4747

4848

tests/mock_vws/test_model_target_web_api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ def test_client_credentials_management(
469469
response=create_response,
470470
status_codes=HTTPStatus.CREATED,
471471
)
472-
client_id = create_response.json()["client_id"]
472+
client_id = create_response.json()["client_id"] # ty: ignore[unsound-assignment]
473473
client_secret = create_response.json()["client_secret"] # pyrefly: ignore [unknown-variable-type]
474474

475475
list_response = model_target_get(
@@ -2062,7 +2062,7 @@ def test_dataset_is_visible_to_the_other_dataset_type(
20622062
response=create_response,
20632063
status_codes=HTTPStatus.CREATED,
20642064
)
2065-
dataset_uuid = create_response.json()["uuid"]
2065+
dataset_uuid = create_response.json()["uuid"] # ty: ignore[unsound-assignment]
20662066

20672067
other_status_response = model_target_get(
20682068
url=f"{_VWS_HOST}{other_path}/{dataset_uuid}/status",

tests/mock_vws/test_query.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,7 +1025,7 @@ def _add_and_wait_for_targets(
10251025
num_targets: int,
10261026
) -> None:
10271027
"""Add targets with the given image."""
1028-
target_ids: Iterable[str] = set()
1028+
target_ids: Iterable[str] = set() # ty: ignore[unsound-assignment]
10291029
for _ in range(num_targets):
10301030
target_id = vws_client.add_target(
10311031
name=uuid.uuid4().hex,
@@ -1034,7 +1034,7 @@ def _add_and_wait_for_targets(
10341034
active_flag=True,
10351035
application_metadata=None,
10361036
)
1037-
target_ids = {*target_ids, target_id}
1037+
target_ids = {*target_ids, target_id} # ty: ignore[unsound-assignment]
10381038

10391039
for created_target_id in target_ids:
10401040
vws_client.wait_for_target_processed(target_id=created_target_id)

0 commit comments

Comments
 (0)