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

Conversation

igalic
Copy link
Collaborator

@igalic igalic commented Sep 17, 2017

install flake8-mutable (and, just to be sure, flake8-builtins;) to check
for these things, as reported in #38.

gronke
gronke previously approved these changes Sep 17, 2017
@igalic
Copy link
Collaborator Author

igalic commented Sep 17, 2017

i think we can do better…

igalic and others added 19 commits September 19, 2017 19:43
install flake8-mutable (and, just to be sure, flake8-builtins;) to check
for these things, as reported in #38.
given the amount of changes we've recently made, it makes no sense to
copare against the arbitrary 0.0.0 tag we made, just for this script.

Instead we install flake8-mypy, and replace our test with a single call
to flake8.
(type in this case;)

while we're at it, also change the the call-site to named params
i don't know what input is, but flake8-builtin says to not shadow it.
okay.
we provide missing types for py-libzfs, ucl, texttable, etc.
when the config doesn't exist
@@ -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! 💜

@@ -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.

Copy link
Collaborator Author

@igalic igalic left a comment

Choose a reason for hiding this comment

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

some soft review, would love to read your explanation for some of the refactorings

would've loved to read it in the commit message even more ;)

@@ -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.


user_properties: set = set()

data: dict = {
def __init__(self, defaults: dict={}) -> None:
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

doesn't this make defaults mutable?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

not according to flake8-mutable.

@@ -26,11 +26,38 @@
import iocage.lib.Config.Jail.BaseConfig


class JailConfigDefaults(iocage.lib.Config.Jail.BaseConfig.BaseConfig):
class DefaultsUserData(dict):
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

can you briefly explain what happened.

Copy link
Member

@gronke gronke Sep 19, 2017

Choose a reason for hiding this comment

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

JailConfigDefaults should return all default properties as data, but only the user overrides as user_data, so that only manual overrides are saved to defaults.json. It was not sufficient to provide a reduced copy of self.data as user_data because some properties were references. DefaultsUserData goes one level deeper and intercepts setting individual attributes, so that we no longer need to pass the reduced copy of self.data.

pool.create(name, {})
dataset = self.zfs.get_dataset(name)
target_pool.create(dataset_name, {})
dataset = self.zfs.get_dataset(dataset_name)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

thanks ;)

**resource_args
)

if not new and (("id" not in data) or (data["id"] is None)):
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 looks like a candidate for encapsulation ;)

Copy link
Member

Choose a reason for hiding this comment

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

It's below 80 characters!!!1 😼

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yea, but, the logic is too much for my tired brain 😩

def dataset(self, value: libzfs.ZFSDataset):
self._set_dataset(value)

@property
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

what happened here?

Copy link
Member

Choose a reason for hiding this comment

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

It's implemented by the parent class. This overrides are no longer needed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

aye

@gronke gronke merged commit 6e84749 into master Sep 19, 2017
@gronke gronke deleted the flake8/more-tests branch September 19, 2017 20:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants