-
Notifications
You must be signed in to change notification settings - Fork 11
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
Conversation
i think we can do better… |
525108e
to
721ca83
Compare
2313bae
to
07e1fb9
Compare
07e1fb9
to
c895b1b
Compare
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
c795c8e
to
abec92d
Compare
@@ -54,21 +54,21 @@ class ZFS: | |||
datasets = ... # type: Any | |||
errno = ... # type: Any | |||
errstr = ... # type: Any | |||
pools = ... # type: Any | |||
pools: List[ZFSPool] = ... |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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.
There was a problem hiding this 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 |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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)): |
There was a problem hiding this comment.
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 ;)
There was a problem hiding this comment.
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 😼
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what happened here?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aye
install flake8-mutable (and, just to be sure, flake8-builtins;) to check
for these things, as reported in #38.