Skip to content

Commit

Permalink
ruff D200 rule (#983)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcSkovMadsen authored Dec 8, 2024
1 parent 0d73ff5 commit 10dfc27
Show file tree
Hide file tree
Showing 35 changed files with 86 additions and 259 deletions.
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 @@ -163,9 +163,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 @@ -189,9 +187,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 @@ -250,9 +246,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 @@ -468,9 +462,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 @@ -527,9 +519,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 @@ -738,9 +728,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 @@ -893,9 +881,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 @@ -911,9 +897,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 @@ -1790,9 +1774,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 @@ -1889,34 +1871,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 @@ -2585,9 +2559,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 @@ -2616,9 +2588,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 @@ -2795,9 +2765,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 @@ -3162,9 +3130,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

0 comments on commit 10dfc27

Please sign in to comment.