Skip to content

Commit eb02342

Browse files
authored
NO-JIRA: chore(pyright): fix types in the checked code so that Pyright passes (opendatahub-io#1008)
* NO-JIRA: chore(pyright): fix types in the checked code so that Pyright passes * /Users/jdanek/IdeaProjects/notebooks/tests/containers/socket_proxy.py:129:20 - error: Module cannot be used as a type (reportGeneralTypeIssues) * /Users/jdanek/IdeaProjects/notebooks/tests/containers/conftest.py:174:40 - error: Expected class but received "(iterable: Iterable[object], /) -> bool" (reportGeneralTypeIssues) * /Users/jdanek/IdeaProjects/notebooks/tests/containers/conftest.py:174:40 - error: Expected class but received "(iterable: Iterable[object], /) -> bool" (reportGeneralTypeIssues) * /Users/jdanek/IdeaProjects/notebooks/tests/containers/kubernetes_utils.py:97:32 - error: Attribute type cannot use type variable "T@__init__" scoped to local method (reportGeneralTypeIssues) * /Users/jdanek/IdeaProjects/notebooks/ci/package_versions.py:63:34 - warning: "TypedDict" cannot be used in this context (reportInvalidTypeForm) /Users/jdanek/IdeaProjects/notebooks/ci/package_versions.py:63:52 - warning: "Software" is not defined (reportUndefinedVariable) /Users/jdanek/IdeaProjects/notebooks/ci/package_versions.py:63:63 - error: Expected class but received "dict[str, type[str]]" (reportGeneralTypeIssues) /Users/jdanek/IdeaProjects/notebooks/ci/package_versions.py:63:63 - warning: Dictionary expression not allowed in type expression (reportInvalidTypeForm) /Users/jdanek/IdeaProjects/notebooks/ci/package_versions.py:67:33 - warning: Call expression not allowed in type expression (reportInvalidTypeForm)
1 parent 449c899 commit eb02342

File tree

6 files changed

+42
-35
lines changed

6 files changed

+42
-35
lines changed

.pre-commit-config.yaml

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,27 @@ repos:
66
rev: 0.6.13
77
hooks:
88
- id: uv-lock
9-
# # https://github.com/astral-sh/ruff-pre-commit
10-
# - repo: https://github.com/astral-sh/ruff-pre-commit
11-
# rev: v0.11.4
12-
# hooks:
13-
# - id: ruff
14-
# types_or: [ python, pyi ]
15-
# args: [ --fix ]
16-
# files: 'ci/.*|tests/.*'
17-
# - id: ruff-format
18-
# types_or: [ python, pyi ]
19-
# files: 'ci/.*|tests/.*'
20-
# # https://pre-commit.com/#new-hooks
21-
# - repo: local
22-
# hooks:
23-
# # https://github.com/microsoft/pyright/issues/3612
24-
# # https://github.com/RobertCraigie/pyright-python#pre-commit
25-
# - id: pyright
26-
# name: Run Pyright on all files
27-
# # entry: /bin/bash -c 'find. -name "*.py" | xargs pyright --pythonversion 3.12'
28-
# entry: uv run pyright --pythonversion 3.12
29-
# pass_filenames: true
30-
# types_or: [ python, pyi ]
31-
# language: system
32-
# files: 'ci/.*|tests/.*'
9+
# # https://github.com/astral-sh/ruff-pre-commit
10+
# - repo: https://github.com/astral-sh/ruff-pre-commit
11+
# rev: v0.11.4
12+
# hooks:
13+
# - id: ruff
14+
# types_or: [python, pyi]
15+
# args: [ --fix ]
16+
# files: 'ci/.*|tests/.*'
17+
# - id: ruff-format
18+
# types_or: [python, pyi]
19+
# files: 'ci/.*|tests/.*'
20+
# # https://pre-commit.com/#new-hooks
21+
- repo: local
22+
hooks:
23+
# https://github.com/microsoft/pyright/issues/3612
24+
# https://github.com/RobertCraigie/pyright-python#pre-commit
25+
- id: pyright
26+
name: Run Pyright on all files
27+
# entry: /bin/bash -c 'find. -name "*.py" | xargs pyright --pythonversion 3.12'
28+
entry: uv run pyright --pythonversion 3.12
29+
pass_filenames: true
30+
types_or: [python, pyi]
31+
language: system
32+
files: 'ci/.*|tests/.*'

ci/cached-builds/konflux_generate_component_build_pipelines.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import re
44
import pathlib
5+
from typing import Any
56

67
import yaml
78

@@ -760,7 +761,7 @@ def component_build_pipeline(component_name, dockerfile_path, is_pr: bool = True
760761
}
761762

762763

763-
def when[T: any](condition: bool, if_true: T, if_false: T) -> T:
764+
def when[T: Any](condition: bool, if_true: T, if_false: T) -> T:
764765
"""Returns either if_true or if_false depending on condition.
765766
The if_true and if_false expressions are always evaluated.
766767

ci/package_versions.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import pathlib
1010
import typing
1111
import unittest
12+
from typing import Any
1213

1314
import yaml
1415

@@ -23,7 +24,7 @@
2324
# unused for now
2425
@dataclasses.dataclass
2526
class Manifest:
26-
_data: any
27+
_data: Any
2728

2829
@property
2930
def name(self) -> str:
@@ -38,9 +39,14 @@ def tags(self) -> list[Tag]:
3839
return [Tag(tag) for tag in self._data['spec']['tags']]
3940

4041

42+
class _Software(typing.TypedDict):
43+
name: str
44+
version: str
45+
46+
4147
@dataclasses.dataclass()
4248
class Tag:
43-
_data: any
49+
_data: Any
4450

4551
@property
4652
def name(self) -> str:
@@ -59,11 +65,11 @@ def outdated(self) -> bool:
5965
return self._data['annotations']['opendatahub.io/image-tag-outdated'] == 'true'
6066

6167
@property
62-
def sw_general(self) -> list[typing.TypedDict("Software", {"name": str, "version": str})]:
68+
def sw_general(self) -> list[_Software]:
6369
return json.loads(self._data['annotations']['opendatahub.io/notebook-software'])
6470

6571
@property
66-
def sw_python(self) -> list[typing.TypedDict("Software", {"name": str, "version": str})]:
72+
def sw_python(self) -> list[_Software]:
6773
return json.loads(self._data['annotations']['opendatahub.io/notebook-python-dependencies'])
6874

6975

tests/containers/conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import logging
44
import os
55
import platform
6-
from typing import Iterable, Callable, TYPE_CHECKING
6+
from typing import Any, Callable, TYPE_CHECKING
77

88
import testcontainers.core.config
99
import testcontainers.core.container
@@ -171,7 +171,7 @@ class TestFrame:
171171
"""
172172

173173
def __init__(self):
174-
self.resources: list[tuple[any, callable]] = []
174+
self.resources: list[tuple[Any, Callable]] = []
175175

176176
def append[T](self, resource: T, cleanup_func: Callable[[T], None] = None) -> T:
177177
"""Runs the Context manager lifecycle on the resource,

tests/containers/kubernetes_utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,9 @@ def test_get_username(self):
9292
assert username is not None and len(username) > 0
9393

9494

95-
class TestFrame:
96-
def __init__[T](self):
97-
self.stack: list[tuple[T, Callable[[T], None] | None]] = []
95+
class TestFrame[S]:
96+
def __init__(self):
97+
self.stack: list[tuple[S, Callable[[S], None] | None]] = []
9898

9999
def defer_resource[T: ocp_resources.resource.Resource](self, resource: T, wait=False,
100100
destructor: Callable[[T], None] | None = None) -> T:

tests/containers/socket_proxy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def _handle_client(self, client_socket):
126126
client_socket.send(data)
127127

128128

129-
def _rst_socket(s: socket):
129+
def _rst_socket(s: socket.socket) -> None:
130130
"""Closing a SO_LINGER socket will RST it
131131
https://stackoverflow.com/questions/46264404/how-can-i-reset-a-tcp-socket-in-python
132132
"""

0 commit comments

Comments
 (0)