Skip to content
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

Enable Ruff d200 rule #983

Open
wants to merge 1 commit into
base: enhancement/ruff-D-rule
Choose a base branch
from
Open
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
16 changes: 4 additions & 12 deletions numbergen/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""
Callable objects that generate numbers according to different distributions.
"""
"""Callable objects that generate numbers according to different distributions."""

import random
import operator
Expand Down Expand Up @@ -241,9 +239,7 @@ def _rational(self, val):


def __getstate__(self):
"""
Avoid Hashlib.md5 TypeError in deepcopy (hashlib issue)
"""
"""Avoid Hashlib.md5 TypeError in deepcopy (hashlib issue)"""
d = self.__dict__.copy()
d.pop('_digest')
d.pop('_hash_struct')
Expand Down Expand Up @@ -374,9 +370,7 @@ def _initialize_random_state(self, seed=None, shared=True, name=None):


def _verify_constrained_hash(self):
"""
Warn if the object name is not explicitly set.
"""
"""Warn if the object name is not explicitly set."""
changed_params = self.param.values(onlychanged=True)
if self.time_dependent and ('name' not in changed_params):
self.param.log(param.WARNING, "Default object name used to set the seed: "
Expand Down Expand Up @@ -575,9 +569,7 @@ def __call__(self):


class ScaledTime(NumberGenerator, TimeDependent):
"""
The current time multiplied by some conversion factor.
"""
"""The current time multiplied by some conversion factor."""

factor = param.Number(default=1.0, doc="""
The factor to be multiplied by the current time value.""")
Expand Down
20 changes: 5 additions & 15 deletions param/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ class ParamFutureWarning(ParamWarning, FutureWarning):
"""

class Skip(Exception):
"""
Exception that allows skipping an update when resolving a reference.
"""
"""Exception that allows skipping an update when resolving a reference."""

def _deprecated(extra_msg="", warning_cat=ParamDeprecationWarning):
def decorator(func):
Expand Down Expand Up @@ -208,19 +206,15 @@ def _is_mutable_container(value):


def full_groupby(l, key=lambda x: x):
"""
Groupby implementation which does not require a prior sort
"""
"""Groupby implementation which does not require a prior sort"""
d = defaultdict(list)
for item in l:
d[key(item)].append(item)
return d.items()


def iscoroutinefunction(function):
"""
Whether the function is an asynchronous generator or a coroutine.
"""
"""Whether the function is an asynchronous generator or a coroutine."""
# Partial unwrapping not required starting from Python 3.11.0
# See https://github.com/holoviz/param/pull/894#issuecomment-1867084447
while isinstance(function, functools.partial):
Expand All @@ -231,9 +225,7 @@ def iscoroutinefunction(function):
)

async def _to_thread(func, /, *args, **kwargs):
"""
Polyfill for asyncio.to_thread in Python < 3.9
"""
"""Polyfill for asyncio.to_thread in Python < 3.9"""
loop = asyncio.get_running_loop()
ctx = contextvars.copy_context()
func_call = functools.partial(ctx.run, func, *args, **kwargs)
Expand Down Expand Up @@ -289,9 +281,7 @@ def flatten(line):
def accept_arguments(
f: Callable[Concatenate[CallableT, P], R]
) -> Callable[P, Callable[[CallableT], R]]:
"""
Decorator for decorators that accept arguments
"""
"""Decorator for decorators that accept arguments"""
@functools.wraps(f)
def _f(*args: P.args, **kwargs: P.kwargs) -> Callable[[CallableT], R]:
return lambda actual_f: f(actual_f, *args, **kwargs)
Expand Down
4 changes: 1 addition & 3 deletions param/ipython.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,9 +350,7 @@ def params(self, parameter_s='', namespaces=None):


class IPythonDisplay:
"""
Reactive display handler that updates the output.
"""
"""Reactive display handler that updates the output."""

enabled = True

Expand Down
68 changes: 17 additions & 51 deletions param/parameterized.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,7 @@ def eval_function_with_deps(function):
return function(*args, **kwargs)

def resolve_value(value, recursive=True):
"""
Resolves the current value of a dynamic reference.
"""
"""Resolves the current value of a dynamic reference."""
if not recursive:
pass
elif isinstance(value, (list, tuple)):
Expand All @@ -190,9 +188,7 @@ def resolve_value(value, recursive=True):
return value

def resolve_ref(reference, recursive=False):
"""
Resolves all parameters a dynamic reference depends on.
"""
"""Resolves all parameters a dynamic reference depends on."""
if recursive:
if isinstance(reference, (list, tuple, set)):
return [r for v in reference for r in resolve_ref(v, recursive)]
Expand Down Expand Up @@ -251,9 +247,7 @@ def __repr__(self):

@contextmanager
def logging_level(level):
"""
Temporarily modify param's logging level.
"""
"""Temporarily modify param's logging level."""
level = level.upper()
levels = [DEBUG, INFO, WARNING, ERROR, CRITICAL, VERBOSE]
level_names = ['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL', 'VERBOSE']
Expand Down Expand Up @@ -469,9 +463,7 @@ def _getattr(obj, attr):


def no_instance_params(cls):
"""
Disables instance parameters on the class
"""
"""Disables instance parameters on the class"""
cls._param__private.disable_instance_params = True
return cls

Expand Down Expand Up @@ -528,9 +520,7 @@ def _f(self, obj, val):


def get_method_owner(method):
"""
Gets the instance that owns the supplied method
"""
"""Gets the instance that owns the supplied method"""
if not inspect.ismethod(method):
return None
if isinstance(method, partial):
Expand Down Expand Up @@ -739,9 +729,7 @@ def _skip_event(*events, **kwargs):


def extract_dependencies(function):
"""
Extract references from a method or function that declares the references.
"""
"""Extract references from a method or function that declares the references."""
subparameters = list(function._dinfo['dependencies'])+list(function._dinfo['kw'].values())
params = []
for p in subparameters:
Expand Down Expand Up @@ -894,9 +882,7 @@ class Watcher(_Watcher):
"""

def __new__(cls_, *args, **kwargs):
"""
Allows creating Watcher without explicit precedence value.
"""
"""Allows creating Watcher without explicit precedence value."""
values = dict(zip(cls_._fields, args))
values.update(kwargs)
if 'precedence' not in values:
Expand All @@ -912,9 +898,7 @@ def __str__(self):


class ParameterMetaclass(type):
"""
Metaclass allowing control over creation of Parameter classes.
"""
"""Metaclass allowing control over creation of Parameter classes."""

def __new__(mcs, classname, bases, classdict):

Expand Down Expand Up @@ -1791,9 +1775,7 @@ def compare_mapping(cls, obj1, obj2):


class _ParametersRestorer:
"""
Context-manager to handle the reset of parameter values after an update.
"""
"""Context-manager to handle the reset of parameter values after an update."""

def __init__(self, *, parameters, restore, refs=None):
self._parameters = parameters
Expand Down Expand Up @@ -1890,34 +1872,26 @@ def __setstate__(self, state):
setattr(self, k, v)

def __getitem__(self_, key):
"""
Returns the class or instance parameter
"""
"""Returns the class or instance parameter"""
inst = self_.self
if inst is None:
return self_._cls_parameters[key]
p = self_.objects(instance=False)[key]
return _instantiated_parameter(inst, p)

def __dir__(self_):
"""
Adds parameters to dir
"""
"""Adds parameters to dir"""
return super().__dir__() + list(self_._cls_parameters)

def __iter__(self_):
"""
Iterates over the parameters on this object.
"""
"""Iterates over the parameters on this object."""
yield from self_._cls_parameters

def __contains__(self_, param):
return param in self_._cls_parameters

def __getattr__(self_, attr):
"""
Extends attribute access to parameter objects.
"""
"""Extends attribute access to parameter objects."""
cls = self_.__dict__.get('cls')
if cls is None: # Class not initialized
raise AttributeError
Expand Down Expand Up @@ -2591,9 +2565,7 @@ def trigger(self_, *param_names):
self_._state_watchers += watchers

def _update_event_type(self_, watcher, event, triggered):
"""
Returns an updated Event object with the type field set appropriately.
"""
"""Returns an updated Event object with the type field set appropriately."""
if triggered:
event_type = 'triggered'
else:
Expand Down Expand Up @@ -2622,9 +2594,7 @@ def _execute_watcher(self, watcher, events):
pass

def _call_watcher(self_, watcher, event):
"""
Invoke the given watcher appropriately given an Event object.
"""
"""Invoke the given watcher appropriately given an Event object."""
if self_._TRIGGER:
pass
elif watcher.onlychanged and (not self_._changed(event)):
Expand Down Expand Up @@ -2801,9 +2771,7 @@ def deserialize_value(self_, pname, value, mode='json'):
return serializer.deserialize_parameter_value(self_or_cls, pname, value)

def schema(self_, safe=False, subset=None, mode='json'):
"""
Returns a schema for the parameters on this Parameterized object.
"""
"""Returns a schema for the parameters on this Parameterized object."""
self_or_cls = self_.self_or_cls
if mode not in Parameter._serializers:
raise ValueError(f'Mode {mode!r} not in available serialization formats {list(Parameter._serializers.keys())!r}')
Expand Down Expand Up @@ -3173,9 +3141,7 @@ def _watch(self_, fn, parameter_names, what='value', onlychanged=True, queued=Fa
return watcher

def unwatch(self_, watcher):
"""
Remove the given Watcher object (from `watch` or `watch_values`) from this object's list.
"""
"""Remove the given Watcher object (from `watch` or `watch_values`) from this object's list."""
try:
self_._register_watcher('remove', watcher, what=watcher.what)
except Exception:
Expand Down
Loading