Skip to content

Commit 70c21a2

Browse files
Merge pull request #1994 from kili-technology/chore/upgrade-pyright
chore: bump pyright to 1.1.407 and remove unused libs
2 parents b7ac86b + 1cfaa97 commit 70c21a2

File tree

18 files changed

+140
-63
lines changed

18 files changed

+140
-63
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ jobs:
5151
python -m pip install --upgrade pip
5252
pip install -e ".[dev]"
5353
- name: Run pyright
54-
run: pyright .
54+
run: pyright src/kili
5555

5656
unit-integration-test:
5757
timeout-minutes: 15

pyproject.toml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,11 @@ dev = [
7373
# linting
7474
"pre-commit >= 3.3.0, < 4.0.0",
7575
"pylint == 4.0.3",
76-
"pyright ==1.1.347",
76+
"pyright ==1.1.407",
7777
# notebooks tests
7878
"nbformat",
7979
"nbconvert",
8080
"ipykernel",
81-
# profiling
82-
"pyinstrument",
83-
# dead code detection
84-
"vulture==2.11",
85-
"dead==1.5.2",
8681
# optional dependencies
8782
"kili-formats[all] == 1.0.0",
8883
"opencv-python >= 4.0.0, < 5.0.0",

src/kili/client.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
import os
66
import sys
77
import warnings
8-
from typing import Optional, Union
8+
from pathlib import Path
9+
from typing import Optional, TypedDict, Union
910

1011
from kili.adapters.authentification import is_api_key_valid
1112
from kili.adapters.http_client import HttpClient
@@ -40,6 +41,13 @@
4041
warnings.filterwarnings("default", module="kili", category=DeprecationWarning)
4142

4243

44+
class GraphQLClientParams(TypedDict, total=False):
45+
"""Parameters for GraphQLClient initialization."""
46+
47+
enable_schema_caching: bool
48+
graphql_schema_cache_dir: Optional[Union[str, Path]]
49+
50+
4351
class FilterPoolFullWarning(logging.Filter):
4452
"""Filter out the specific urllib3 warning related to the connection pool."""
4553

@@ -82,7 +90,7 @@ def __init__(
8290
api_endpoint: Optional[str] = None,
8391
verify: Optional[Union[bool, str]] = None,
8492
client_name: GraphQLClientName = GraphQLClientName.SDK,
85-
graphql_client_params: Optional[dict[str, object]] = None,
93+
graphql_client_params: Optional[GraphQLClientParams] = None,
8694
) -> None:
8795
"""Initialize Kili client.
8896
@@ -166,7 +174,7 @@ def __init__(
166174
client_name=client_name,
167175
verify=self.verify,
168176
http_client=self.http_client,
169-
**(graphql_client_params or {}), # pyright: ignore[reportGeneralTypeIssues]
177+
**(graphql_client_params or {}),
170178
)
171179
self.kili_api_gateway = KiliAPIGateway(self.graphql_client, self.http_client)
172180
self.internal = InternalClientMethods(self.kili_api_gateway)

src/kili/client_domain.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from functools import cached_property
66
from typing import TYPE_CHECKING, Optional, Union
77

8+
from kili.client import GraphQLClientParams
89
from kili.client import Kili as KiliLegacy
910
from kili.core.graphql.graphql_client import GraphQLClientName
1011

@@ -46,7 +47,7 @@ def __init__(
4647
api_key: Optional[str] = None,
4748
api_endpoint: Optional[str] = None,
4849
verify: Optional[Union[bool, str]] = None,
49-
graphql_client_params: Optional[dict[str, object]] = None,
50+
graphql_client_params: Optional[GraphQLClientParams] = None,
5051
) -> None:
5152
"""Initialize Kili client (domain mode).
5253

src/kili/core/graphql/graphql_client.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,10 @@ def _get_graphql_schema_from_endpoint(self) -> str:
192192
fetch_schema_from_transport=True,
193193
introspection_args=self._get_introspection_args(),
194194
) as session:
195-
return print_schema(session.client.schema) # pyright: ignore[reportGeneralTypeIssues]
195+
schema = session.client.schema
196+
if schema is None:
197+
raise ValueError("Failed to fetch GraphQL schema from endpoint")
198+
return print_schema(schema)
196199

197200
def _cache_graphql_schema(self, graphql_schema_path: Path, schema_str: str) -> None:
198201
"""Cache the graphql schema on disk."""
@@ -332,7 +335,7 @@ def _raw_execute(
332335
)
333336
transport = self._gql_client.transport
334337
if transport:
335-
headers = transport.response_headers # pyright: ignore[reportGeneralTypeIssues]
338+
headers = transport.response_headers # pyright: ignore[reportAttributeAccessIssue]
336339
returned_complexity = int(headers.get("x-complexity", 0)) if headers else 0
337340
self.complexity_consumed += returned_complexity
338341
return res

src/kili/core/helpers.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@ def format_result(
3535
"""
3636
formatted_json = format_json(result[name], http_client)
3737
if object_ is None:
38-
return formatted_json # pyright: ignore[reportGeneralTypeIssues]
38+
return formatted_json # pyright: ignore[reportReturnType]
3939
if isinstance(formatted_json, list):
4040
if get_origin(object_) is list:
4141
obj = get_args(object_)[0]
42-
return [obj(element) for element in formatted_json] # pyright: ignore[reportGeneralTypeIssues]
42+
return [obj(element) for element in formatted_json] # pyright: ignore[reportReturnType]
4343
# the legacy "orm" objects fall into this category.
44-
return [object_(element) for element in formatted_json] # pyright: ignore[reportGeneralTypeIssues]
44+
return [object_(element) for element in formatted_json] # pyright: ignore[reportReturnType,reportCallIssue]
4545

46-
return object_(formatted_json)
46+
return object_(formatted_json) # pyright: ignore[reportCallIssue]
4747

4848

4949
def get_mime_type(path: str):

src/kili/entrypoints/mutations/asset/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ def append_many_to_dataset(
197197
if value is not None:
198198
assets = [{**assets[i], key: value[i]} for i in range(nb_data)]
199199
created_asset_ids = import_assets(
200-
self, # pyright: ignore[reportGeneralTypeIssues]
200+
self, # pyright: ignore[reportArgumentType]
201201
project_id=ProjectId(project_id),
202202
assets=assets,
203203
disable_tqdm=disable_tqdm,

src/kili/entrypoints/mutations/plugins/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def upload_plugin(
5757
raise TypeError('"plugin_path is nullish, please provide a value')
5858

5959
return PluginUploader(
60-
self, # pyright: ignore[reportGeneralTypeIssues]
60+
self, # pyright: ignore[reportArgumentType]
6161
plugin_path,
6262
plugin_name,
6363
verbose,
@@ -106,7 +106,7 @@ def create_webhook(
106106
>>> kili.create_webhook(webhook_url='https://my-custom-url-publicly-accessible/', plugin_name='my webhook', header='...')
107107
"""
108108
return WebhookUploader(
109-
self, # pyright: ignore[reportGeneralTypeIssues]
109+
self, # pyright: ignore[reportArgumentType]
110110
webhook_url,
111111
plugin_name,
112112
header,
@@ -148,7 +148,7 @@ def update_webhook(
148148
>>> kili.update_webhook(webhook_url='https://my-custom-url-publicly-accessible/', plugin_name='my webhook', header='...')
149149
"""
150150
return WebhookUploader(
151-
self, # pyright: ignore[reportGeneralTypeIssues]
151+
self, # pyright: ignore[reportArgumentType]
152152
new_webhook_url,
153153
plugin_name,
154154
new_header,
@@ -246,7 +246,7 @@ def update_plugin(
246246
raise TypeError('"plugin_name is nullish, please provide a value')
247247

248248
return PluginUploader(
249-
self, # pyright: ignore[reportGeneralTypeIssues]
249+
self, # pyright: ignore[reportArgumentType]
250250
plugin_path,
251251
plugin_name,
252252
verbose,

src/kili/entrypoints/mutations/project/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ def copy_project( # pylint: disable=too-many-arguments
253253
"The 'copy_json_interface' and 'copy_quality_settings' arguments are deprecated."
254254
)
255255

256-
return ProjectCopier(self).copy_project( # pyright: ignore[reportGeneralTypeIssues]
256+
return ProjectCopier(self).copy_project( # pyright: ignore[reportArgumentType]
257257
from_project_id,
258258
title,
259259
description,

src/kili/entrypoints/queries/plugins/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def get_plugin_status(
108108
>>> kili.get_plugin_status(plugin_name="my_plugin_name")
109109
"""
110110
return PluginUploader(
111-
self, # pyright: ignore[reportGeneralTypeIssues]
111+
self, # pyright: ignore[reportArgumentType]
112112
"",
113113
plugin_name,
114114
verbose,

0 commit comments

Comments
 (0)