Skip to content

Commit

Permalink
Fix mypy ignore pattern(#115)
Browse files Browse the repository at this point in the history
  • Loading branch information
rayrayraykk authored Mar 29, 2024
1 parent 19929de commit b702de1
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion examples/distributed/user_proxy_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
class UserProxyAgent(UserAgent):
"""User proxy agent class"""

def reply( # type: ignore [override]
def reply( # type: ignore[override]
self,
x: dict = None,
required_keys: Optional[Union[list[str], str]] = None,
Expand Down
8 changes: 4 additions & 4 deletions src/agentscope/agents/rpc_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@
)


def rpc_servicer_method( # type: ignore [no-untyped-def]
def rpc_servicer_method( # type: ignore[no-untyped-def]
func,
):
"""A decorator used to identify that the specific method is an rpc agent
servicer method, which can only be run in the rpc server process.
"""

def inner(rpc_agent, msg): # type: ignore [no-untyped-def]
def inner(rpc_agent, msg): # type: ignore[no-untyped-def]
if not rpc_agent.is_servicer:
error_msg = f"Detect main process try to use rpc servicer method \
[{func.__name__}]"
Expand Down Expand Up @@ -139,15 +139,15 @@ def reply(self, x: dict = None) -> dict:
value=x.serialize() if x is not None else "",
)
return PlaceholderMessage(
**deserialize(res_msg), # type: ignore [arg-type]
**deserialize(res_msg), # type: ignore[arg-type]
)

def observe(self, x: Union[dict, Sequence[dict]]) -> None:
if self.client is None:
self._launch_server()
self.client.call_func(
func_name="_observe",
value=serialize(x), # type: ignore [arg-type]
value=serialize(x), # type: ignore[arg-type]
)

def stop(self) -> None:
Expand Down
6 changes: 3 additions & 3 deletions src/agentscope/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ def _get_model_wrapper(model_type: str) -> Type[ModelWrapperBase]:
`Type[ModelWrapperBase]`: The corresponding model wrapper class.
"""
if model_type in ModelWrapperBase.type_registry:
return ModelWrapperBase.type_registry[ # type: ignore [return-value]
return ModelWrapperBase.type_registry[ # type: ignore[return-value]
model_type
]
elif model_type in ModelWrapperBase.registry:
return ModelWrapperBase.registry[ # type: ignore [return-value]
return ModelWrapperBase.registry[ # type: ignore[return-value]
model_type
]
elif model_type in ModelWrapperBase.deprecated_type_registry:
Expand All @@ -81,7 +81,7 @@ def _get_model_wrapper(model_type: str) -> Type[ModelWrapperBase]:
f"Model type [{model_type}] will be deprecated in future releases,"
f" please use [{cls.model_type}] instead.",
)
return cls # type: ignore [return-value]
return cls # type: ignore[return-value]
else:
logger.warning(
f"Unsupported model_type [{model_type}],"
Expand Down
4 changes: 2 additions & 2 deletions src/agentscope/pipelines/functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def forlooppipeline(
# check condition
if break_func(x):
break
return x # type: ignore [return-value]
return x # type: ignore[return-value]


def whilelooppipeline(
Expand Down Expand Up @@ -176,4 +176,4 @@ def whilelooppipeline(
x = _operators(loop_body_operators, x)
# check condition
i += 1
return x # type: ignore [return-value]
return x # type: ignore[return-value]
2 changes: 1 addition & 1 deletion src/agentscope/utils/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ def get_monitor(
raise NotImplementedError(
"Monitor with type [{type}] is not implemented.",
)
return cls._instance # type: ignore [return-value]
return cls._instance # type: ignore[return-value]

@classmethod
def flush(cls) -> None:
Expand Down
14 changes: 7 additions & 7 deletions tests/monitor_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ def test_register_exists_remove(self) -> None:
# metric content
metric = self.monitor.get_metric("token_num")
self.assertIsNotNone(metric)
self.assertEqual(metric["unit"], "token") # type: ignore [index]
self.assertEqual(metric["quota"], 1000) # type: ignore [index]
self.assertEqual(metric["unit"], "token") # type: ignore[index]
self.assertEqual(metric["quota"], 1000) # type:ignore[index]
# remove a registered metric
self.assertTrue(self.monitor.remove("token_num"))
self.assertFalse(self.monitor.exists("token_num"))
Expand Down Expand Up @@ -155,9 +155,9 @@ def test_get(self) -> None:
self.assertIsNone(self.monitor.get_metric("token_num"))
metric = self.monitor.get_metric("agentB.token_num")
self.assertIsNotNone(metric)
self.assertEqual(metric["value"], 0) # type: ignore [index]
self.assertEqual(metric["unit"], "token") # type: ignore [index]
self.assertEqual(metric["quota"], 100) # type: ignore [index]
self.assertEqual(metric["value"], 0) # type: ignore[index]
self.assertEqual(metric["unit"], "token") # type: ignore[index]
self.assertEqual(metric["quota"], 100) # type: ignore[index]
self.assertEqual(self.monitor.get_metrics(r"cost"), {})
agenta_metrics = self.monitor.get_metrics("agentA")
self.assertEqual(len(agenta_metrics.keys()), 2)
Expand Down Expand Up @@ -213,7 +213,7 @@ def test_register_budget(self) -> None:
"agent_A.gpt-4",
)
self.assertLess(
self.monitor.get_value( # type: ignore [arg-type]
self.monitor.get_value( # type: ignore[arg-type]
"agent_A.gpt-4.cost",
),
5,
Expand All @@ -227,7 +227,7 @@ def test_register_budget(self) -> None:
),
)
self.assertEqual(
self.monitor.get_value( # type: ignore [arg-type]
self.monitor.get_value( # type: ignore[arg-type]
"agent_A.gpt-4.cost",
),
3,
Expand Down
6 changes: 3 additions & 3 deletions tests/rpc_agent_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
class DemoRpcAgent(AgentBase):
"""A demo Rpc agent for test usage."""

def __init__(self, **kwargs) -> None: # type: ignore [no-untyped-def]
def __init__(self, **kwargs) -> None: # type: ignore[no-untyped-def]
super().__init__(**kwargs)
self.id = 0

Expand Down Expand Up @@ -138,7 +138,7 @@ def test_single_rpc_agent_server(self) -> None:
self.assertTrue(isinstance(placeholder_result, PlaceholderMessage))
self.assertEqual(placeholder_result.name, "a")
self.assertEqual(
placeholder_result["name"], # type: ignore [call-overload]
placeholder_result["name"], # type: ignore[call-overload]
"a",
)
self.assertTrue(
Expand All @@ -163,7 +163,7 @@ def test_single_rpc_agent_server(self) -> None:
self.assertEqual(msg_result.content, msg.content)
self.assertEqual(msg_result.id, 0)
# check id increase
msg = agent_a(msg_result) # type: ignore [arg-type]
msg = agent_a(msg_result) # type: ignore[arg-type]
self.assertEqual(msg.id, 1)

def test_connect_to_an_existing_rpc_server(self) -> None:
Expand Down

0 comments on commit b702de1

Please sign in to comment.