Skip to content

Commit

Permalink
Typing corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
yasserfarouk committed Nov 15, 2024
1 parent ba10616 commit da192d4
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 20 deletions.
10 changes: 7 additions & 3 deletions src/negmas/concurrent/chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from collections import defaultdict, namedtuple
from dataclasses import dataclass

from negmas.preferences.base_ufun import BaseUtilityFunction

from ..common import NegotiatorMechanismInterface, MechanismAction, MechanismState
from ..mechanisms import Mechanism, MechanismStepResult
from ..negotiators import Negotiator
Expand Down Expand Up @@ -68,6 +70,7 @@ def join(
state: MechanismState,
*,
preferences: Preferences | None = None,
ufun: BaseUtilityFunction | None = None,
role: str = "negotiator",
) -> bool:
to_join = super().join(nmi, state, preferences=preferences, role=role)
Expand Down Expand Up @@ -143,6 +146,7 @@ def join(
state: MechanismState,
*,
preferences: Preferences | None = None,
ufun: BaseUtilityFunction | None = None,
role: str = "negotiator",
) -> bool:
to_join = super().join(nmi, state, preferences=preferences, role=role)
Expand Down Expand Up @@ -212,11 +216,11 @@ def respond(


class ChainNegotiationsMechanism(
Mechanism[MechanismState, MechanismAction, ChainNMI, ChainNegotiator]
Mechanism[ChainNMI, MechanismState, MechanismAction, ChainNegotiator]
):
def __init__(self, initial_state: MechanismState | None = None, *args, **kwargs):
super().__init__(
initial_state if initial_state else MechanismState() * args, **kwargs
initial_state if initial_state else MechanismState(), *args, **kwargs
)
self.__chain: list[ChainNegotiator | None] = []
self.__next_agent = 0
Expand All @@ -226,7 +230,7 @@ def __init__(self, initial_state: MechanismState | None = None, *args, **kwargs)
self.__temp_agreements: dict[int, Outcome | None] = defaultdict(lambda: None)

def _get_ami(
self, negotiator: Negotiator, role: str
self, negotiator: ChainNegotiator, role: str
) -> NegotiatorMechanismInterface:
"""
Returns a chain AMI instead of the standard AMI.
Expand Down
4 changes: 2 additions & 2 deletions src/negmas/helpers/strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def shorten(name: str, length: int = 4, common_parts=COMMON_NAME_PARTS) -> str:
continue
needed -= 1
caps.append(c)
return "".join(caps[:length])
return str("".join(caps[:length]))


def unique_name(base, add_time=True, add_host=False, rand_digits=8, sep="/") -> str:
Expand Down Expand Up @@ -368,4 +368,4 @@ def humanize_time(
parts.append("%2d%s%s" % (n, unit, ""))
else:
parts.append("%2d%s%s" % (n, unit, ""))
return "".join(parts)
return str("".join(parts))
8 changes: 5 additions & 3 deletions src/negmas/inout.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,18 +412,20 @@ def calc_extra_stats(
continue
us = (u1, u2)
fu_, findx = pareto_frontier(
us, outcomes=outcomes, sort_by_welfare=True
us, # type: ignore
outcomes=outcomes,
sort_by_welfare=True,
)
foutcomes_ = [outcomes[i] for i in findx]
fu[(u1.name, u2.name)], fo[(u1.name, u2.name)] = (
fu_,
[outcomes[_] for _ in findx],
)
pts = nash_points((u1, u2), fu_, outcomes=outcomes)
pts = nash_points((u1, u2), fu_, outcomes=outcomes) # type: ignore
nu[(u1.name, u2.name)], nindx = pts[0] if pts else (None, None)
no[(u1.name, u2.name)] = foutcomes_[nindx] if nindx else None
ol[(u1.name, u2.name)] = opposition_level(
(u1, u2),
(u1, u2), # type: ignore
outcomes=outcomes,
max_utils=(minmax[i][1], minmax[j][1]),
max_tests=max_cardinality,
Expand Down
22 changes: 11 additions & 11 deletions src/negmas/mechanisms.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
MechanismState,
NegotiatorInfo,
NegotiatorMechanismInterface,
ReactiveStrategy,
TraceElement,
)
from negmas.events import Event, EventSource
Expand Down Expand Up @@ -680,6 +679,11 @@ def _get_nmi(self, negotiator: TNegotiator) -> TNMI:
_ = negotiator
return self.nmi

def _get_ami(self, negotiator: TNegotiator) -> TNMI:
_ = negotiator
warnings.deprecated("_get_ami is depricated. Use `get_nmi` instead of it")
return self.nmi

def add(
self,
negotiator: TNegotiator,
Expand Down Expand Up @@ -1050,12 +1054,13 @@ def step(self, action: dict[str, TAction] | None = None) -> TState:
etatime = self.expected_remaining_time
etatime = etatime if etatime is not None else float("inf")
if remaining is not None:
_eta = (
humanize_time(
min((_elapsed * remaining) / self.current_step, etatime)
)
+ f" {remaining} steps"
tt = humanize_time(
min((_elapsed * remaining) / self.current_step, etatime)
)
if tt is not None:
_eta = tt + f" {remaining} steps"
else:
_eta = "--"
else:
_eta = "--"
print(
Expand Down Expand Up @@ -1561,11 +1566,6 @@ def plot(self, **kwargs) -> Any:
"""A method for plotting a negotiation session."""
_ = kwargs

def _get_ami(self, negotiator: ReactiveStrategy) -> TNMI:
_ = negotiator
warnings.deprecated("_get_ami is depricated. Use `get_nmi` instead of it")
return self.nmi

def __iter__(self):
return self

Expand Down
2 changes: 1 addition & 1 deletion src/negmas/preferences/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -1720,7 +1720,7 @@ def is_irrational(outcome, ufun: BaseUtilityFunction):
)
if v < nearest_val:
nearest_val = v
return sqrt(nearest_val)
return float(sqrt(nearest_val))


def conflict_level(
Expand Down

0 comments on commit da192d4

Please sign in to comment.