Skip to content

Commit

Permalink
update mypy, address issues
Browse files Browse the repository at this point in the history
  • Loading branch information
shadeofblue committed Jun 3, 2024
1 parent 7ecbab7 commit 012b083
Show file tree
Hide file tree
Showing 10 changed files with 16 additions and 14 deletions.
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ black = "^23.1.0"
factory-boy = "^3.2.0"
isort = "^5.10.1"
liccheck = "^0.4.7"
mypy = "^0.942"
mypy = "^1.10.0"
poethepoet = "^0.8.0"
pytest = "^6.2"
pytest-asyncio = "^0.14"
Expand All @@ -63,6 +63,7 @@ flake8 = "^5"
flake8-docstrings = "^1.6"
Flake8-pyproject = "^1.2.2"


[tool.poe.tasks]
checks = {sequence = ["checks_codestyle", "checks_typing", "checks_license"], help = "Run all available code checks"}
checks_codestyle = {sequence = ["_checks_codestyle_flake8", "_checks_codestyle_isort", "_checks_codestyle_black"], help = "Run only code style checks"}
Expand Down
2 changes: 1 addition & 1 deletion yapapi/contrib/strategy/provider_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def __init__(self, base_strategy: BaseMarketStrategy, is_allowed: IsAllowedType)

async def score_offer(self, offer: OfferProposal) -> float:
if inspect.iscoroutinefunction(self._is_allowed):
allowed = await self._is_allowed(offer.issuer) # type: ignore
allowed = await self._is_allowed(offer.issuer)
else:
allowed = self._is_allowed(offer.issuer)

Expand Down
4 changes: 2 additions & 2 deletions yapapi/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ def task_id(self) -> str:
return self.task.id

@property
def task_data(self) -> "yapapi.executor.task.TaskData":
def task_data(self):
return self.task.data


Expand Down Expand Up @@ -525,7 +525,7 @@ class CommandStdErr(CommandEvent):
@attr.s(auto_attribs=True, repr=False)
class TaskAccepted(TaskEvent):
@property
def result(self) -> "yapapi.executor.task.TaskResult":
def result(self):
assert self.task._result is not None
return self.task._result

Expand Down
6 changes: 3 additions & 3 deletions yapapi/payload/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ class Aliased:

@classmethod
def _to_aliased_dict(cls, values: dict):
for f in fields(cls):
for f in fields(cls): # type: ignore [arg-type]
alias = f.metadata.get("alias")
if alias and f.name in values:
values[alias] = values.pop(f.name)

@classmethod
def _from_aliased_dict(cls, values: dict):
for f in fields(cls):
for f in fields(cls): # type: ignore [arg-type]
alias = f.metadata.get("alias")
if alias and alias in values:
values[f.name] = values.pop(alias)
Expand Down Expand Up @@ -329,7 +329,7 @@ def parse_obj(cls, obj: Dict, by_alias: bool = False) -> "Manifest":

@classmethod
async def generate(
cls, image_hash: str = None, outbound_urls: List[str] = None, **kwargs
cls, image_hash: Optional[str] = None, outbound_urls: Optional[List[str]] = None, **kwargs
) -> "Manifest":
if image_hash is not None:
kwargs["payload.0.hash"] = image_hash
Expand Down
2 changes: 1 addition & 1 deletion yapapi/payload/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class PackageException(Exception):
"""Exception raised on any problems related to the package repository."""


@dataclass # type: ignore # mypy issue #5374
@dataclass
class Package(Payload):
"""Description of a task package (e.g. a VM image) deployed on the provider nodes."""

Expand Down
6 changes: 3 additions & 3 deletions yapapi/props/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def property_fields(cls) -> typing.List[Field]:
"""
return [
f
for f in fields(cls)
for f in fields(cls) # type: ignore [arg-type]
if PROP_KEY in f.metadata
and f.metadata.get(PROP_MODEL_FIELD_TYPE, ModelFieldType.property)
== ModelFieldType.property
Expand All @@ -110,7 +110,7 @@ def constraint_fields(cls) -> typing.List[Field]:
"""Return a list of constraint fields of a Model."""
return [
f
for f in fields(cls)
for f in fields(cls) # type: ignore [arg-type]
if PROP_KEY in f.metadata
and f.metadata.get(PROP_MODEL_FIELD_TYPE, None) == ModelFieldType.constraint
]
Expand Down Expand Up @@ -279,7 +279,7 @@ def constraint_model_serialize(m: Model) -> List[str]:
"""
return [
constraint_to_str(getattr(m, f.name), f)
for f in fields(type(m))
for f in fields(type(m)) # type: ignore [arg-type]
if f.metadata.get(PROP_MODEL_FIELD_TYPE, "") == ModelFieldType.constraint
]

Expand Down
2 changes: 1 addition & 1 deletion yapapi/props/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def ensure(self, constraint: str):
def add(self, m: Model):
"""Add properties from the specified model to this demand definition."""
kv = m.property_keys()
base = asdict(m)
base = asdict(m) # type: ignore [call-overload]

for name in kv.names():
prop_id = kv.__dict__[name]
Expand Down
2 changes: 1 addition & 1 deletion yapapi/props/com.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Counter(enum.Enum):
UNKNOWN = ""


@dataclass(frozen=True) # type: ignore # mypy doesn't allow abstract methods in dataclasses
@dataclass(frozen=True)
class Com(Model):
"""Base model representing the payment model used."""

Expand Down
1 change: 1 addition & 0 deletions yapapi/script/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@


class Command(abc.ABC):
@abc.abstractmethod
def evaluate(self) -> BatchCommand:
"""Evaluate and serialize this command."""

Expand Down
2 changes: 1 addition & 1 deletion yapapi/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class AsyncWrapper(AsyncContextManager):
_task: Optional[asyncio.Task]

def __init__(self, wrapped: Callable):
self._wrapped = wrapped # type: ignore # suppress mypy issue #708
self._wrapped = wrapped
self._args_buffer = asyncio.Queue()
self._loop = asyncio.get_event_loop()
self._task = None
Expand Down

0 comments on commit 012b083

Please sign in to comment.