Skip to content

Commit fa0f4b8

Browse files
committed
fix python casting annotation issue
1 parent b4b4b91 commit fa0f4b8

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

python/mesc/load.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from . import validation
1010

1111
if typing.TYPE_CHECKING:
12-
from typing_extensions import cast, Literal, Any
12+
from typing_extensions import Literal, Any
1313
from .types import RpcConfig
1414

1515

@@ -41,7 +41,7 @@ def read_config_data() -> RpcConfig:
4141

4242
# validate
4343
validation.validate(config)
44-
return cast(RpcConfig, config)
44+
return config # type: ignore
4545

4646

4747
@typing.overload
@@ -72,9 +72,7 @@ def read_env_config(*, validate: bool = True) -> RpcConfig | Any:
7272
# validate config
7373
if validate:
7474
validation.validate(config)
75-
return cast(RpcConfig, config)
76-
else:
77-
return config
75+
return config
7876

7977

8078
@typing.overload
@@ -124,6 +122,4 @@ def read_file_config(
124122
# validate config
125123
if validate:
126124
validation.validate(config)
127-
return cast(RpcConfig, config)
128-
else:
129-
return config
125+
return config

tests/adapters/python

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,30 @@ from __future__ import annotations
44

55
import argparse
66
import json
7-
from typing import Sequence, cast, Union
7+
import typing
88

9-
from mesc.types import Endpoint, EndpointQuery
109
import mesc
1110

11+
if typing.TYPE_CHECKING:
12+
from typing import Sequence, Union
13+
from mesc.types import Endpoint, EndpointQuery
14+
1215

1316
def run_query(query: EndpointQuery) -> Union[Endpoint, Sequence[Endpoint], None]:
1417
if query["query_type"] == "default_endpoint":
15-
default_fields = cast(mesc.types.DefaultEndpointQuery, query["fields"])
18+
default_fields: mesc.types.DefaultEndpointQuery = query["fields"]
1619
return mesc.get_default_endpoint(**default_fields)
1720
elif query["query_type"] == "endpoint_by_name":
18-
name_fields = cast(mesc.types.EndpointNameQuery, query["fields"])
21+
name_fields: mesc.types.EndpointNameQuery = query["fields"]
1922
return mesc.get_endpoint_by_name(**name_fields)
2023
elif query["query_type"] == "endpoint_by_network":
21-
network_fields = cast(mesc.types.EndpointNetworkQuery, query["fields"])
24+
network_fields: mesc.types.EndpointNetworkQuery = query["fields"]
2225
return mesc.get_endpoint_by_network(**network_fields)
2326
elif query["query_type"] == "user_input":
24-
user_input_fields = cast(mesc.types.UserInputQuery, query["fields"])
27+
user_input_fields: mesc.types.UserInputQuery = query["fields"]
2528
return mesc.get_endpoint_by_query(**user_input_fields)
2629
elif query["query_type"] == "multi_endpoint":
27-
multi_endpoint_fields = cast(mesc.types.MultiEndpointQuery, query["fields"])
30+
multi_endpoint_fields: mesc.types.MultiEndpointQuery = query["fields"]
2831
return mesc.find_endpoints(**multi_endpoint_fields)
2932
elif query["query_type"] == "global_metadata":
3033
return mesc.get_global_metadata(**query["fields"])

0 commit comments

Comments
 (0)