Skip to content

flake8: check for mutable function parameters #107

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

Merged
merged 19 commits into from
Sep 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ sudo: false
env:
- MYPYPATH="$TRAVIS_BUILD_DIR/.travis/mypy-stubs"
install:
- pip3 install flake8 mypy
- pip3 install flake8-mutable flake8-builtins flake8-mypy
script:
- ".travis/flake8.sh"
- mypy iocage
- flake8 --exclude=".*" --exclude=__init__.py --ignore=E203,W391
34 changes: 0 additions & 34 deletions .travis/flake8.sh

This file was deleted.

53 changes: 29 additions & 24 deletions .travis/mypy-stubs/libzfs.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# NOTE: This dynamically typed stub was automatically generated by stubgen.

from datetime import date
from typing import Any
from typing import Any, List, Dict, Optional

DatasetType = ... # type: Any
DiffFileType = ... # type: Any
Expand Down Expand Up @@ -54,21 +54,21 @@ class ZFS:
datasets = ... # type: Any
errno = ... # type: Any
errstr = ... # type: Any
pools = ... # type: Any
pools: List[ZFSPool] = ...
Copy link
Collaborator Author

@igalic igalic Sep 19, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This whole thing is amazing
thank you very much for the effort of typing this package! 💜

snapshots = ... # type: Any
__pyx_vtable__ = ... # type: Any
def __init__(self, *args, **kwargs): ...
def __init__(self, *args, **kwargs) -> None: ...
def create(self, *args, **kwargs): ...
def describe_resume_token(self, *args, **kwargs): ...
def destroy(self, *args, **kwargs): ...
def destroy(self, name: str) -> None: ...
def export_pool(self, *args, **kwargs): ...
def find_import(self, *args, **kwargs): ...
def generate_history_opts(self, *args, **kwargs): ...
def get(self, *args, **kwargs): ...
def get_dataset(self, *args, **kwargs): ...
def get_dataset_by_path(self, *args, **kwargs): ...
def get_dataset(self, name: str) -> ZFSDataset: ...
def get_dataset_by_path(self, *args, **kwargs) -> ZFSDataset: ...
def get_object(self, *args, **kwargs): ...
def get_snapshot(self, *args, **kwargs): ...
def get_snapshot(self, name: str) -> ZFSSnapshot: ...
def history_vdevs_list(self, *args, **kwargs): ...
def import_pool(self, *args, **kwargs): ...
def receive(self, *args, **kwargs): ...
Expand All @@ -88,23 +88,28 @@ class ZFSBookmark(ZFSObject):

class ZFSDataset(ZFSObject):
bookmarks = ... # type: Any
children = ... # type: Any
children: List[ZFSDataset] = ...
children_recursive = ... # type: Any
dependents = ... # type: Any
mountpoint = ... # type: Any
snapshots = ... # type: Any
mountpoint: str = ...
snapshots: List[ZFSSnapshot]= ...
snapshots_recursive = ... # type: Any
__pyx_vtable__ = ... # type: Any
def __init__(self, *args, **kwargs): ...
def destroy_snapshot(self, *args, **kwargs): ...
def diff(self, *args, **kwargs): ...
def get_send_progress(self, *args, **kwargs): ...
def mount(self, *args, **kwargs): ...
def mount_recursive(self, *args, **kwargs): ...
def mount(self, *args, **kwargs) -> None: ...
def mount_recursive(self, *args, **kwargs) -> None: ...
def promote(self, *args, **kwargs): ...
def receive(self, *args, **kwargs): ...
def send(self, *args, **kwargs): ...
def snapshot(self, *args, **kwargs): ...
def snapshot(
self,
name: str,
fsopts: Optional[Dict[str, str]],
recursive: bool=False
) -> None: ...
def umount(self, *args, **kwargs): ...
def umount_recursive(self, *args, **kwargs): ...
def __getstate__(self): ...
Expand Down Expand Up @@ -167,8 +172,8 @@ class ZFSPool:
def __init__(self, *args, **kwargs): ...
def attach_vdevs(self, *args, **kwargs): ...
def clear(self, *args, **kwargs): ...
def create(self, *args, **kwargs): ...
def delete(self, *args, **kwargs): ...
def create(self, *args, **kwargs) -> None: ...
def delete(self, *args, **kwargs) -> None: ...
def start_scrub(self, *args, **kwargs): ...
def stop_scrub(self, *args, **kwargs): ...
def upgrade(self, *args, **kwargs): ...
Expand All @@ -193,14 +198,14 @@ class ZFSProperty:
def __setstate_cython__(self, *args, **kwargs): ...

class ZFSPropertyDict(dict):
def __init__(self, *args, **kwargs): ...
def get(self, *args, **kwargs): ...
def __init__(self, *args, **kwargs) -> None: ...
def get(self, *args, **kwargs) -> ZFSProperty: ...
def has_key(self, *args, **kwargs): ...
def items(self, *args, **kwargs): ...
def iterkeys(self, *args, **kwargs): ...
def itervalues(self, *args, **kwargs): ...
def keys(self, *args, **kwargs): ...
def refresh(self, *args, **kwargs): ...
def refresh(self) -> None: ...
def setdefault(self, *args, **kwargs): ...
def update(self, *args, **kwargs): ...
def values(self, *args, **kwargs): ...
Expand All @@ -214,16 +219,16 @@ class ZFSPropertyDict(dict):

class ZFSSnapshot(ZFSObject):
holds = ... # type: Any
mountpoint = ... # type: Any
mountpoint: str = ...
parent = ... # type: Any
snapshot_name = ... # type: Any
def __init__(self, *args, **kwargs): ...
snapshot_name: str = ...
def __init__(self, *args, **kwargs) -> None: ...
def bookmark(self, *args, **kwargs): ...
def clone(self, *args, **kwargs): ...
def clone(self, name: str, opts: Optional[Dict[str, str]]) -> None: ...
def delete(self, *args, **kwargs): ...
def hold(self, *args, **kwargs): ...
def release(self, *args, **kwargs): ...
def rollback(self, *args, **kwargs): ...
def rollback(self, force: bool=False) -> None: ...
def send(self, *args, **kwargs): ...
def __getstate__(self): ...
def __reduce_cython__(self, *args, **kwargs): ...
Expand All @@ -234,7 +239,7 @@ class ZFSUserProperty(ZFSProperty):
rawvalue = ... # type: Any
source = ... # type: Any
value = ... # type: Any
def __init__(self, *args, **kwargs): ...
def __init__(self, *args, **kwargs) -> None: ...
def __reduce_cython__(self, *args, **kwargs): ...
def __setstate_cython__(self, *args, **kwargs): ...

Expand Down
24 changes: 14 additions & 10 deletions .travis/mypy-stubs/texttable.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# NOTE: This dynamically typed stub was automatically generated by stubgen.

from typing import Any
from typing import Any, List

class ArraySizeError(Exception):
msg = ... # type: Any
Expand All @@ -15,14 +15,18 @@ class Texttable:
VLINES = ... # type: Any
def __init__(self, max_width: int = ...) -> None: ...
def reset(self): ...
def set_chars(self, array): ...
def set_chars(self, array: List): ...
def set_deco(self, deco): ...
def set_cols_align(self, array): ...
def set_cols_valign(self, array): ...
def set_cols_dtype(self, array): ...
def set_cols_width(self, array): ...
def set_cols_align(self, array: List): ...
def set_cols_valign(self, array: List): ...
def set_cols_dtype(self, array: List): ...
def set_cols_width(self, array: List): ...
def set_precision(self, width): ...
def header(self, array): ...
def add_row(self, array): ...
def add_rows(self, rows, header: bool = ...): ...
def draw(self): ...
def header(self, array: List): ...
def add_row(self, array: List): ...
def add_rows(
self,
rows: List[List[str]],
header: bool = ...
): ...
def draw(self) -> str: ...
4 changes: 2 additions & 2 deletions .travis/mypy-stubs/ucl.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ UCL_EMIT_JSON_COMPACT = ... # type: int
UCL_EMIT_MSGPACK = ... # type: int
UCL_EMIT_YAML = ... # type: int

def dump(*args, **kwargs): ...
def load(*args, **kwargs): ...
def dump(*args, **kwargs) -> str: ...
def load(*args, **kwargs) -> dict: ...
def validate(*args, **kwargs): ...
42 changes: 19 additions & 23 deletions __main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,40 +22,36 @@
# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
"""The main CLI for ioc."""
import locale
import os
import re
import signal
import subprocess as su
import sys

import click

from iocage.cli import cli


def main_safe():
try:
main()
except BaseException as e:
return e
try:
main()
except BaseException as e:
return e


def main():
cli(prog_name="iocage")
cli(prog_name="iocage")


if __name__ == "__main__":
coverdir = os.environ.get("IOCAGE_TRACE", None)
if coverdir is None:
main()
else:
import trace
tracer = trace.Trace(
ignoredirs=[sys.prefix, sys.exec_prefix],
trace=0,
count=1)
tracer.run("main_safe()")
r = tracer.results()
r.write_results(show_missing=True, coverdir=coverdir)
print(f"Iocage Trace written to: {coverdir}")
coverdir = os.environ.get("IOCAGE_TRACE", None)
if coverdir is None:
main()
else:
import trace
tracer = trace.Trace(
ignoredirs=[sys.prefix, sys.exec_prefix],
trace=0,
count=1
)
tracer.run("main_safe()")
r = tracer.results()
r.write_results(show_missing=True, coverdir=coverdir)
print(f"Iocage Trace written to: {coverdir}")
14 changes: 7 additions & 7 deletions iocage/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
# 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.
from iocage.lib import errors, events
from iocage.lib.Host import Host
from iocage.lib.Jail import Jail
from iocage.lib.Jails import Jails
from iocage.lib.Logger import Logger
from iocage.lib.Release import Release
from iocage.lib.Releases import Releases
from iocage.lib import errors, events # noqa: F401
from iocage.lib.Host import Host # noqa: F401
from iocage.lib.Jail import Jail # noqa: F401
from iocage.lib.Jails import Jails # noqa: F401
from iocage.lib.Logger import Logger # noqa: F401
from iocage.lib.Release import Release # noqa: F401
from iocage.lib.Releases import Releases # noqa: F401
3 changes: 2 additions & 1 deletion iocage/cli/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def cli(ctx, release, template, count, props, pkglist, basejail, basejail_type,
errors = False
for i in range(count):

jail = iocage.lib.Jail.Jail(
jail = iocage.lib.Jail.JailGenerator(
jail_data,
logger=logger,
host=host,
Expand All @@ -158,6 +158,7 @@ def cli(ctx, release, template, count, props, pkglist, basejail, basejail_type,
msg = f"{jail.humanreadable_name} successfully created!{suffix}"
logger.log(msg)
except:
raise
msg = f"{jail.humanreadable_name} could not be created!{suffix}"
logger.warn(msg)

Expand Down
4 changes: 2 additions & 2 deletions iocage/cli/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,12 @@ def _print_table(
try:
sort_index = columns.index(sort_key)
except ValueError:
sort_index = None
sort_index = -1

for resource in resources:
table_data.append(_lookup_resource_values(resource, columns))

if sort_index is not None:
if sort_index > -1:
table_data.sort(key=lambda x: x[sort_index])

if show_header:
Expand Down
24 changes: 15 additions & 9 deletions iocage/cli/set.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,15 @@
@click.pass_context
@click.argument("props", nargs=-1)
@click.argument("jail", nargs=1, required=True)
def cli(ctx, props, jail):
def cli(
ctx: click.core.Context,
props: typing.Tuple[str, ...],
jail: str
) -> None:
"""Get a list of jails and print the property."""

logger = ctx.parent.logger
parent: typing.Any = ctx.parent
logger: iocage.lib.Logger.Logger = parent.logger
host = iocage.lib.Host.HostGenerator(logger=logger)

# Defaults
Expand All @@ -66,15 +71,15 @@ def cli(ctx, props, jail):

updated_jail_count = 0

for jail in ioc_jails:
for ioc_jail in ioc_jails: # type: iocage.lib.Jail.JailGenerator
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how the heck does that need a hint?? that feels like a bug in mypy

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can try to remove. Being explicit in other places should have fixed it anyway!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you're right
works without it, too.


updated_properties = set_properties(props, jail)
updated_properties = set_properties(props, ioc_jail)

if len(updated_properties) == 0:
logger.screen(f"Jail '{jail.humanreadable_name}' unchanged")
logger.screen(f"Jail '{ioc_jail.humanreadable_name}' unchanged")
else:
logger.screen(
f"Jail '{jail.humanreadable_name}' updated: " +
f"Jail '{ioc_jail.humanreadable_name}' updated: " +
", ".join(updated_properties)
)

Expand All @@ -88,7 +93,7 @@ def cli(ctx, props, jail):


def set_properties(
properties: typing.List[str],
properties: typing.Iterable[str],
target: 'iocage.lib.LaunchableResource.LaunchableResource'
) -> set:

Expand All @@ -107,6 +112,7 @@ def set_properties(
del target.config[key]
updated_properties.add(key)
except:
raise
pass
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this pass can probz be removed.


if len(updated_properties) > 0:
Expand All @@ -115,5 +121,5 @@ def set_properties(
return updated_properties


def _is_setter_property(property_string):
return "=" in property_string
def _is_setter_property(property_string: str) -> bool:
return ("=" in property_string)
Loading