Skip to content

Commit

Permalink
Upgrade pydocstyle to 4.0.0, do not run in tox (home-assistant#25667)
Browse files Browse the repository at this point in the history
* Upgrade pydocstyle to 4.0.0 and flake8-docstrings to 1.3.1

http://www.pydocstyle.org/en/4.0.0/release_notes.html#july-6th-2019

* Address pydocstyle D413's

* tox: do not run pydocstyle

Does not seem to add any value over flake8-docstrings (and would have
needed a D202 exclusion).
  • Loading branch information
scop authored and pvizeli committed Aug 4, 2019
1 parent c748d8c commit 49a5dda
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 105 deletions.
68 changes: 37 additions & 31 deletions homeassistant/components/filter/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from functools import partial
from copy import copy
from datetime import timedelta
from typing import Optional

import voluptuous as vol

Expand Down Expand Up @@ -333,17 +334,21 @@ def __repr__(self):


class Filter:
"""Filter skeleton.
"""Filter skeleton."""

Args:
window_size (int): size of the sliding window that holds previous
values
precision (int): round filtered value to precision value
entity (string): used for debugging only
"""

def __init__(self, name, window_size=1, precision=None, entity=None):
"""Initialize common attributes."""
def __init__(
self,
name,
window_size: int = 1,
precision: Optional[int] = None,
entity: Optional[str] = None,
):
"""Initialize common attributes.
:param window_size: size of the sliding window that holds previous values
:param precision: round filtered value to precision value
:param entity: used for debugging only
"""
if isinstance(window_size, int):
self.states = deque(maxlen=window_size)
self.window_unit = WINDOW_SIZE_UNIT_NUMBER_EVENTS
Expand Down Expand Up @@ -394,14 +399,19 @@ class RangeFilter(Filter):
Determines if new state is in the range of upper_bound and lower_bound.
If not inside, lower or upper bound is returned instead.
Args:
upper_bound (float): band upper bound
lower_bound (float): band lower bound
"""

def __init__(self, entity, lower_bound=None, upper_bound=None):
"""Initialize Filter."""
def __init__(
self,
entity,
lower_bound: Optional[float] = None,
upper_bound: Optional[float] = None,
):
"""Initialize Filter.
:param upper_bound: band upper bound
:param lower_bound: band lower bound
"""
super().__init__(FILTER_NAME_RANGE, entity=entity)
self._lower_bound = lower_bound
self._upper_bound = upper_bound
Expand Down Expand Up @@ -441,13 +451,13 @@ class OutlierFilter(Filter):
"""BASIC outlier filter.
Determines if new state is in a band around the median.
Args:
radius (float): band radius
"""

def __init__(self, window_size, precision, entity, radius):
"""Initialize Filter."""
def __init__(self, window_size, precision, entity, radius: float):
"""Initialize Filter.
:param radius: band radius
"""
super().__init__(FILTER_NAME_OUTLIER, window_size, precision, entity)
self._radius = radius
self._stats_internal = Counter()
Expand Down Expand Up @@ -475,13 +485,9 @@ def _filter_state(self, new_state):

@FILTERS.register(FILTER_NAME_LOWPASS)
class LowPassFilter(Filter):
"""BASIC Low Pass Filter.
Args:
time_constant (int): time constant.
"""
"""BASIC Low Pass Filter."""

def __init__(self, window_size, precision, entity, time_constant):
def __init__(self, window_size, precision, entity, time_constant: int):
"""Initialize Filter."""
super().__init__(FILTER_NAME_LOWPASS, window_size, precision, entity)
self._time_constant = time_constant
Expand All @@ -505,15 +511,15 @@ class TimeSMAFilter(Filter):
"""Simple Moving Average (SMA) Filter.
The window_size is determined by time, and SMA is time weighted.
Args:
type (enum): type of algorithm used to connect discrete values
"""

def __init__(
self, window_size, precision, entity, type
): # pylint: disable=redefined-builtin
"""Initialize Filter."""
"""Initialize Filter.
:param type: type of algorithm used to connect discrete values
"""
super().__init__(FILTER_NAME_TIME_SMA, window_size, precision, entity)
self._time_window = window_size
self.last_leak = None
Expand Down
1 change: 1 addition & 0 deletions homeassistant/components/islamic_prayer_times/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ async def schedule_future_update(hass, sensors, midnight_time, prayer_times_data
calculated midnight = 1:35AM (after traditional midnight)
update time: 1:36AM.
"""
_LOGGER.debug("Scheduling next update for Islamic prayer times")

Expand Down
5 changes: 2 additions & 3 deletions homeassistant/components/lw12wifi/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,8 @@ class LW12WiFi(Light):
def __init__(self, name, lw12_light):
"""Initialise LW-12 WiFi LED Controller.
Args:
name: Friendly name for this platform to use.
lw12_light: Instance of the LW12 controller.
:param name: Friendly name for this platform to use.
:param lw12_light: Instance of the LW12 controller.
"""
self._light = lw12_light
self._name = name
Expand Down
121 changes: 55 additions & 66 deletions homeassistant/components/wunderground/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from datetime import timedelta
import logging
import re
from typing import Any, Callable, Optional, Union

import aiohttp
import async_timeout
Expand Down Expand Up @@ -56,29 +57,25 @@ class WUSensorConfig:

def __init__(
self,
friendly_name,
feature,
value,
unit_of_measurement=None,
friendly_name: Union[str, Callable],
feature: str,
value: Callable[["WUndergroundData"], Any],
unit_of_measurement: Optional[str] = None,
entity_picture=None,
icon="mdi:gauge",
icon: str = "mdi:gauge",
device_state_attributes=None,
device_class=None,
):
"""Constructor.
Args:
friendly_name (string|func): Friendly name
feature (string): WU feature. See:
:param friendly_name: Friendly name
:param feature: WU feature. See:
https://www.wunderground.com/weather/api/d/docs?d=data/index
value (function(WUndergroundData)): callback that
extracts desired value from WUndergroundData object
unit_of_measurement (string): unit of measurement
entity_picture (string): value or callback returning
URL of entity picture
icon (string): icon name or URL
device_state_attributes (dict): dictionary of attributes,
or callable that returns it
:param value: callback that extracts desired value from WUndergroundData object
:param unit_of_measurement: unit of measurement
:param entity_picture: value or callback returning URL of entity picture
:param icon: icon name or URL
:param device_state_attributes: dictionary of attributes, or callable that returns it
"""
self.friendly_name = friendly_name
self.unit_of_measurement = unit_of_measurement
Expand All @@ -95,21 +92,18 @@ class WUCurrentConditionsSensorConfig(WUSensorConfig):

def __init__(
self,
friendly_name,
field,
icon="mdi:gauge",
unit_of_measurement=None,
friendly_name: Union[str, Callable],
field: str,
icon: Optional[str] = "mdi:gauge",
unit_of_measurement: Optional[str] = None,
device_class=None,
):
"""Constructor.
Args:
friendly_name (string|func): Friendly name of sensor
field (string): Field name in the "current_observation"
dictionary.
icon (string): icon name or URL, if None sensor
will use current weather symbol
unit_of_measurement (string): unit of measurement
:param friendly_name: Friendly name of sensor
:field: Field name in the "current_observation" dictionary.
:icon: icon name or URL, if None sensor will use current weather symbol
:unit_of_measurement: unit of measurement
"""
super().__init__(
friendly_name,
Expand All @@ -130,13 +124,14 @@ def __init__(
class WUDailyTextForecastSensorConfig(WUSensorConfig):
"""Helper for defining sensor configurations for daily text forecasts."""

def __init__(self, period, field, unit_of_measurement=None):
def __init__(
self, period: int, field: str, unit_of_measurement: Optional[str] = None
):
"""Constructor.
Args:
period (int): forecast period number
field (string): field name to use as value
unit_of_measurement(string): unit of measurement
:param period: forecast period number
:param field: field name to use as value
:param unit_of_measurement: unit of measurement
"""
super().__init__(
friendly_name=lambda wu: wu.data["forecast"]["txt_forecast"]["forecastday"][
Expand All @@ -161,24 +156,22 @@ class WUDailySimpleForecastSensorConfig(WUSensorConfig):

def __init__(
self,
friendly_name,
period,
field,
wu_unit=None,
ha_unit=None,
friendly_name: str,
period: int,
field: str,
wu_unit: Optional[str] = None,
ha_unit: Optional[str] = None,
icon=None,
device_class=None,
):
"""Constructor.
Args:
period (int): forecast period number
field (string): field name to use as value
wu_unit (string): "fahrenheit", "celsius", "degrees" etc.
see the example json at:
https://www.wunderground.com/weather/api/d/docs?d=data/forecast&MR=1
ha_unit (string): corresponding unit in home assistant
title (string): friendly_name of the sensor
:param friendly_name: friendly_name of the sensor
:param period: forecast period number
:param field: field name to use as value
:param wu_unit: "fahrenheit", "celsius", "degrees" etc. see the example json at:
https://www.wunderground.com/weather/api/d/docs?d=data/forecast&MR=1
:param ha_unit: corresponding unit in home assistant
"""
super().__init__(
friendly_name=friendly_name,
Expand Down Expand Up @@ -213,12 +206,11 @@ def __init__(
class WUHourlyForecastSensorConfig(WUSensorConfig):
"""Helper for defining sensor configurations for hourly text forecasts."""

def __init__(self, period, field):
def __init__(self, period: int, field: int):
"""Constructor.
Args:
period (int): forecast period number
field (int): field name to use as value
:param period: forecast period number
:param field: field name to use as value
"""
super().__init__(
friendly_name=lambda wu: "{} {}".format(
Expand Down Expand Up @@ -274,24 +266,22 @@ class WUAlmanacSensorConfig(WUSensorConfig):

def __init__(
self,
friendly_name,
field,
value_type,
wu_unit,
unit_of_measurement,
icon,
friendly_name: Union[str, Callable],
field: str,
value_type: str,
wu_unit: str,
unit_of_measurement: str,
icon: str,
device_class=None,
):
"""Constructor.
Args:
friendly_name (string|func): Friendly name
field (string): value name returned in 'almanac' dict
as returned by the WU API
value_type (string): "record" or "normal"
wu_unit (string): unit name in WU API
icon (string): icon name or URL
unit_of_measurement (string): unit of measurement
:param friendly_name: Friendly name
:param field: value name returned in 'almanac' dict as returned by the WU API
:param value_type: "record" or "normal"
:param wu_unit: unit name in WU API
:param unit_of_measurement: unit of measurement
:param icon: icon name or URL
"""
super().__init__(
friendly_name=friendly_name,
Expand All @@ -306,11 +296,10 @@ def __init__(
class WUAlertsSensorConfig(WUSensorConfig):
"""Helper for defining field configuration for alerts."""

def __init__(self, friendly_name):
def __init__(self, friendly_name: Union[str, Callable]):
"""Constructor.
Args:
friendly_name (string|func): Friendly name
:param friendly_name: Friendly name
"""
super().__init__(
friendly_name=friendly_name,
Expand Down
1 change: 1 addition & 0 deletions homeassistant/util/ruamel_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def _include_yaml(
Example:
device_tracker: !include device_tracker.yaml
"""
if constructor.name is None:
raise HomeAssistantError(
Expand Down
1 change: 1 addition & 0 deletions homeassistant/util/yaml/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ def _include_yaml(loader: SafeLineLoader, node: yaml.nodes.Node) -> JSON_TYPE:
Example:
device_tracker: !include device_tracker.yaml
"""
fname = os.path.join(os.path.dirname(loader.name), node.value)
return _add_reference(load_yaml(fname), loader, node)
Expand Down
4 changes: 2 additions & 2 deletions requirements_test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ asynctest==0.13.0
black==19.3b0
codecov==2.0.15
coveralls==1.2.0
flake8-docstrings==1.3.0
flake8-docstrings==1.3.1
flake8==3.7.8
mock-open==1.3.1
mypy==0.720
pydocstyle==3.0.0
pydocstyle==4.0.0
pylint==2.3.1
pytest-aiohttp==0.3.0
pytest-cov==2.7.1
Expand Down
4 changes: 2 additions & 2 deletions requirements_test_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ asynctest==0.13.0
black==19.3b0
codecov==2.0.15
coveralls==1.2.0
flake8-docstrings==1.3.0
flake8-docstrings==1.3.1
flake8==3.7.8
mock-open==1.3.1
mypy==0.720
pydocstyle==3.0.0
pydocstyle==4.0.0
pylint==2.3.1
pytest-aiohttp==0.3.0
pytest-cov==2.7.1
Expand Down
1 change: 0 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ commands =
python -m script.gen_requirements_all validate
python -m script.hassfest validate
flake8 {posargs: homeassistant tests script}
pydocstyle {posargs:homeassistant tests}

[testenv:typing]
whitelist_externals=/bin/bash
Expand Down

0 comments on commit 49a5dda

Please sign in to comment.