Skip to content

mypy --strict #181

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 12 commits into from
42 changes: 21 additions & 21 deletions .travis/mypy-stubs/libzfs.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class ZFS:
errno = ... # type: Any
errstr = ... # type: Any
pools: List[ZFSPool] = ...
snapshots = ... # type: Any
snapshots: List[ZFSSnapshot] = ...
__pyx_vtable__ = ... # type: Any
def __init__(self, *args, **kwargs) -> None: ...
def create(self, *args, **kwargs): ...
Expand All @@ -79,7 +79,7 @@ class ZFS:
def __setstate_cython__(self, *args, **kwargs): ...

class ZFSBookmark(ZFSObject):
bookmark_name = ... # type: Any
bookmark_name = ... # type: str
parent = ... # type: Any
def __init__(self, *args, **kwargs): ...
def __getstate__(self): ...
Expand Down Expand Up @@ -123,9 +123,9 @@ class ZFSImportablePool(ZFSPool):
config = ... # type: Any
error_count = ... # type: Any
features = ... # type: Any
name = ... # type: Any
properties = ... # type: Any
root_dataset = ... # type: Any
name: str = ...
properties: List[ZFSProperty] = ...
root_dataset: ZFSDataset = ...
__pyx_vtable__ = ... # type: Any
def __init__(self, *args, **kwargs): ...
def attach_vdev(self, *args, **kwargs): ...
Expand All @@ -135,9 +135,9 @@ class ZFSImportablePool(ZFSPool):
def __setstate_cython__(self, *args, **kwargs): ...

class ZFSObject:
name = ... # type: Any
pool = ... # type: Any
properties = ... # type: Any
name: str = ...
pool: ZFSPool = ...
properties: List[ZFSProperty] = ...
root = ... # type: Any
type = ... # type: Any
def __init__(self, *args, **kwargs): ...
Expand All @@ -157,12 +157,12 @@ class ZFSPool:
features = ... # type: Any
groups = ... # type: Any
guid = ... # type: Any
hostname = ... # type: Any
hostname = ... # type: str
log_vdevs = ... # type: Any
name = ... # type: Any
properties = ... # type: Any
name: str = ...
properties: List[ZFSProperty] = ...
root = ... # type: Any
root_dataset = ... # type: Any
root_dataset: ZFSDataset = ...
root_vdev = ... # type: Any
scrub = ... # type: Any
spare_vdevs = ... # type: Any
Expand All @@ -184,12 +184,12 @@ class ZFSPool:

class ZFSProperty:
allowed_values = ... # type: Any
dataset = ... # type: Any
name = ... # type: Any
dataset: ZFSDataset = ...
name: str = ...
parsed = ... # type: Any
rawvalue = ... # type: Any
source = ... # type: Any
value = ... # type: Any
value: str = ...
def __init__(self, *args, **kwargs): ...
def inherit(self, *args, **kwargs): ...
def refresh(self, *args, **kwargs): ...
Expand Down Expand Up @@ -235,10 +235,10 @@ class ZFSSnapshot(ZFSObject):
def __setstate_cython__(self, *args, **kwargs): ...

class ZFSUserProperty(ZFSProperty):
name = ... # type: Any
name: str = ...
rawvalue = ... # type: Any
source = ... # type: Any
value = ... # type: Any
value: str = ...
def __init__(self, *args, **kwargs) -> None: ...
def __reduce_cython__(self, *args, **kwargs): ...
def __setstate_cython__(self, *args, **kwargs): ...
Expand Down Expand Up @@ -292,8 +292,8 @@ class ZFSVdevStats:
class ZPoolFeature:
description = ... # type: Any
guid = ... # type: Any
name = ... # type: Any
pool = ... # type: Any
name: str = ...
pool: ZFSPool = ...
state = ... # type: Any
def __init__(self, *args, **kwargs): ...
def enable(self, *args, **kwargs): ...
Expand All @@ -303,12 +303,12 @@ class ZPoolFeature:

class ZPoolProperty:
allowed_values = ... # type: Any
name = ... # type: Any
name: str = ...
parsed = ... # type: Any
pool = ... # type: Any
rawvalue = ... # type: Any
source = ... # type: Any
value = ... # type: Any
value: str = ...
def __init__(self, *args, **kwargs): ...
def reset(self, *args, **kwargs): ...
def __getstate__(self): ...
Expand Down
4 changes: 3 additions & 1 deletion .travis/mypy-stubs/ucl.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
#
# NOTE: This dynamically typed stub was automatically generated by stubgen.

from typing import Dict, Any

UCL_EMIT_CONFIG = ... # type: int
UCL_EMIT_JSON = ... # type: int
UCL_EMIT_JSON_COMPACT = ... # type: int
UCL_EMIT_MSGPACK = ... # type: int
UCL_EMIT_YAML = ... # type: int

def dump(*args, **kwargs) -> str: ...
def load(*args, **kwargs) -> dict: ...
def load(*args, **kwargs) -> Dict[str, Any]: ...
def validate(*args, **kwargs): ...
17 changes: 14 additions & 3 deletions iocage/cli/destroy.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@
# POSSIBILITY OF SUCH DAMAGE.
"""stop module for the cli."""
import click
import typing

import iocage.lib.Filter
import iocage.lib.Jail
import iocage.lib.Jails
import iocage.lib.Releases
import iocage.lib.Logger
import iocage.lib.Releases
import iocage.lib.Resource

__rootcmd__ = True
Expand All @@ -45,18 +47,27 @@
help="Destroy the download dataset of the specified RELEASE as"
" well.")
@click.argument("filters", nargs=-1)
def cli(ctx, force, release, recursive, download, filters):
def cli(ctx,
force: bool=False,
release: bool=False,
recursive: bool=False,
download: bool=False,
filters: typing.Optional[iocage.lib.Filter.Terms]=None) -> None:
"""
Looks for the jail supplied and passes the uuid, path and configuration
location to stop_jail.
"""
logger = ctx.parent.logger
host = iocage.lib.Host.Host(logger=logger)

if len(filters) == 0:
if filters is None or len(filters) == 0:
logger.error("No filter specified - cannot select a target to delete")
exit(1)

resources_class: typing.Union[
typing.Type[iocage.lib.Releases.ReleasesGenerator],
typing.Type[iocage.lib.Jails.JailsGenerator]
]
if release is True:
resources_class = iocage.lib.Releases.ReleasesGenerator
else:
Expand Down
7 changes: 5 additions & 2 deletions iocage/cli/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,14 @@ def cli(ctx, prop, _all, _pool, jail, log_level):
print_property(key, value)


def print_property(key, value):
def print_property(key: str, value: str) -> None:
print(f"{key}:{value}")


def _lookup_config_value(resource, key: str) -> typing.Any:
def _lookup_config_value(
resource: 'iocage.lib.Resource.Resource',
key: str
) -> typing.Any:
return iocage.lib.helpers.to_string(resource.config[key])


Expand Down
4 changes: 2 additions & 2 deletions iocage/cli/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def _print_table(
],
columns: list,
show_header: bool,
sort_key: str=None
sort_key: typing.Optional[str]=None
) -> None:

table = texttable.Texttable(max_width=0)
Expand Down Expand Up @@ -210,7 +210,7 @@ def _print_json(

def _lookup_resource_values(resource, columns) -> typing.List[str]:
return list(map(
lambda column: resource.getstring(column),
lambda column: str(resource.getstring(column)),
columns
))

Expand Down
6 changes: 4 additions & 2 deletions iocage/lib/Config/Dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
"""The main CLI for ioc."""
import os.path
import libzfs
import typing

import iocage.lib.Config.Prototype


Expand All @@ -33,7 +35,7 @@ class DatasetConfig(iocage.lib.Config.Prototype.Prototype):

def __init__(
self,
dataset: libzfs.ZFSDataset=None,
dataset: typing.Optional[libzfs.ZFSDataset]=None,
**kwargs
) -> None:

Expand All @@ -48,7 +50,7 @@ def dataset(self) -> libzfs.ZFSDataset:

@property
def file(self) -> str:
return os.path.join(self.dataset.mountpoint, self._file)
return str(os.path.join(self.dataset.mountpoint, self._file))

@file.setter
def file(self, value: str):
Expand Down
8 changes: 6 additions & 2 deletions iocage/lib/Config/File.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,21 @@
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
import typing
import iocage.lib.Config.Prototype

# mypy
import iocage.lib.Logger


class ConfigFile(iocage.lib.Config.Prototype.Prototype):

_file: str

def __init__(
self,
file: str=None,
logger: 'iocage.lib.Logger.Logger'=None
file: typing.Optional[str]=None,
logger: typing.Optional[iocage.lib.Logger.Logger]=None
) -> None:

iocage.lib.Config.Prototype.Prototype.__init__(
Expand Down
Loading