pylint 2.3.0 (#21485)

* pylint 2.3.0

* remove const

*  disable=syntax-error
This commit is contained in:
Daniel Høyer Iversen 2019-02-27 22:10:40 +01:00 committed by David F. Mulcahey
parent 2482816a11
commit 519315f9c8
26 changed files with 47 additions and 57 deletions

View File

@ -170,8 +170,7 @@ class AuthManager:
user = await self.async_get_user_by_credentials(credentials)
if user is None:
raise ValueError('Unable to find the user.')
else:
return user
return user
auth_provider = self._async_get_auth_provider(credentials)

View File

@ -66,7 +66,7 @@ class BloomSky:
self.API_URL, headers={AUTHORIZATION: self._api_key}, timeout=10)
if response.status_code == 401:
raise RuntimeError("Invalid API_KEY")
elif response.status_code != 200:
if response.status_code != 200:
_LOGGER.error("Invalid HTTP response: %s", response.status_code)
return
# Create dictionary keyed off of the device unique id

View File

@ -291,7 +291,7 @@ class DeviceTracker:
"""
if mac is None and dev_id is None:
raise HomeAssistantError('Neither mac or device id passed in')
elif mac is not None:
if mac is not None:
mac = str(mac).upper()
device = self.mac_to_dev.get(mac)
if not device:

View File

@ -216,8 +216,7 @@ def _req_json_rpc(url, session_id, rpcmethod, subsystem, method, **params):
if 'message' in response['error'] and \
response['error']['message'] == "Access denied":
raise PermissionError(response['error']['message'])
else:
raise HomeAssistantError(response['error']['message'])
raise HomeAssistantError(response['error']['message'])
if rpcmethod == "call":
try:

View File

@ -366,8 +366,7 @@ def _get_related_entity_ids(session, entity_filter):
if tryno == RETRIES - 1:
raise
else:
time.sleep(QUERY_RETRY_WAIT)
time.sleep(QUERY_RETRY_WAIT)
def _generate_filter_from_config(config):

View File

@ -345,9 +345,8 @@ class BluesoundPlayer(MediaPlayerDevice):
if raise_timeout:
_LOGGER.info("Timeout: %s", self.host)
raise
else:
_LOGGER.debug("Failed communicating: %s", self.host)
return None
_LOGGER.debug("Failed communicating: %s", self.host)
return None
return data

View File

@ -41,6 +41,5 @@ async def resolve_auth_code(hass, client_id, client_secret, code):
except AuthorizationError as err:
if err.response.status_code == 401:
raise config_flow.CodeInvalid()
else:
raise config_flow.NestAuthError('Unknown error: {} ({})'.format(
err, err.response.status_code))
raise config_flow.NestAuthError('Unknown error: {} ({})'.format(
err, err.response.status_code))

View File

@ -248,7 +248,7 @@ class NFAndroidTVNotificationService(BaseNotificationService):
req = requests.get(url, timeout=DEFAULT_TIMEOUT)
return req.content
elif local_path is not None:
if local_path is not None:
# Check whether path is whitelisted in configuration.yaml
if self.is_allowed_path(local_path):
return open(local_path, "rb")

View File

@ -149,8 +149,7 @@ class PushsaferNotificationService(BaseNotificationService):
response = requests.get(url, timeout=CONF_TIMEOUT)
return self.get_base64(response.content,
response.headers['content-type'])
else:
_LOGGER.warning("url not found in param")
_LOGGER.warning("url not found in param")
return None

View File

@ -152,7 +152,7 @@ class SlackNotificationService(BaseNotificationService):
req = requests.get(url, timeout=CONF_TIMEOUT)
return req.content
elif local_path:
if local_path:
# Check whether path is whitelisted in configuration.yaml
if self.is_allowed_path(local_path):
return open(local_path, 'rb')

View File

@ -81,7 +81,7 @@ async def async_register_panel(
"""Register a new custom panel."""
if js_url is None and html_url is None and module_url is None:
raise ValueError('Either js_url, module_url or html_url is required.')
elif (js_url and html_url) or (module_url and html_url):
if (js_url and html_url) or (module_url and html_url):
raise ValueError('Pass in only one of JS url, Module url or HTML url.')
if config is not None and not isinstance(config, dict):

View File

@ -125,13 +125,13 @@ def execute(hass, filename, source, data=None):
# pylint: disable=too-many-boolean-expressions
if name.startswith('async_'):
raise ScriptError("Not allowed to access async methods")
elif (obj is hass and name not in ALLOWED_HASS or
obj is hass.bus and name not in ALLOWED_EVENTBUS or
obj is hass.states and name not in ALLOWED_STATEMACHINE or
obj is hass.services and name not in ALLOWED_SERVICEREGISTRY or
obj is dt_util and name not in ALLOWED_DT_UTIL or
obj is datetime and name not in ALLOWED_DATETIME or
isinstance(obj, TimeWrapper) and name not in ALLOWED_TIME):
if (obj is hass and name not in ALLOWED_HASS or
obj is hass.bus and name not in ALLOWED_EVENTBUS or
obj is hass.states and name not in ALLOWED_STATEMACHINE or
obj is hass.services and name not in ALLOWED_SERVICEREGISTRY or
obj is dt_util and name not in ALLOWED_DT_UTIL or
obj is datetime and name not in ALLOWED_DATETIME or
isinstance(obj, TimeWrapper) and name not in ALLOWED_TIME):
raise ScriptError("Not allowed to access {}.{}".format(
obj.__class__.__name__, name))

View File

@ -76,5 +76,4 @@ def execute(qry):
if tryno == RETRIES - 1:
raise
else:
time.sleep(QUERY_RETRY_WAIT)
time.sleep(QUERY_RETRY_WAIT)

View File

@ -119,10 +119,9 @@ class CurrencylayerData:
self._resource, params=self._parameters, timeout=10)
if 'error' in result.json():
raise ValueError(result.json()['error']['info'])
else:
self.data = result.json()['quotes']
_LOGGER.debug("Currencylayer data updated: %s",
result.json()['timestamp'])
self.data = result.json()['quotes']
_LOGGER.debug("Currencylayer data updated: %s",
result.json()['timestamp'])
except ValueError as err:
_LOGGER.error("Check Currencylayer API %s", err.args)
self.data = None

View File

@ -44,7 +44,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Set up the Sterling Bank sensor platform."""
from starlingbank import StarlingAccount
from starlingbank import StarlingAccount # pylint: disable=syntax-error
sensors = []
for account in config[CONF_ACCOUNTS]:

View File

@ -34,10 +34,10 @@ def setup_platform(hass, config, add_entities, discovery_info=None) -> None:
name = config.get(CONF_NAME)
mac_addr = config[CONF_MAC]
flip_on_off = config[CONF_FLIP_ON_OFF]
add_entities([Switchmate(mac_addr, name, flip_on_off)], True)
add_entities([SwitchmateEntity(mac_addr, name, flip_on_off)], True)
class Switchmate(SwitchDevice):
class SwitchmateEntity(SwitchDevice):
"""Representation of a Switchmate."""
def __init__(self, mac, name, flip_on_off) -> None:

View File

@ -628,7 +628,7 @@ class BaseTelegramBotEntity:
self.hass.bus.async_fire(event, event_data)
return True
elif ATTR_CALLBACK_QUERY in data:
if ATTR_CALLBACK_QUERY in data:
event = EVENT_TELEGRAM_CALLBACK
data = data.get(ATTR_CALLBACK_QUERY)
message_ok, event_data = self._get_message_data(data)
@ -642,6 +642,6 @@ class BaseTelegramBotEntity:
self.hass.bus.async_fire(event, event_data)
return True
else:
_LOGGER.warning("Message with unknown data received: %s", data)
return True
_LOGGER.warning("Message with unknown data received: %s", data)
return True

View File

@ -61,7 +61,7 @@ def message_handler(handler):
"""Initialize the messages handler instance."""
super().__init__(handler)
def check_update(self, update):
def check_update(self, update): # pylint: disable=no-self-use
"""Check is update valid."""
return isinstance(update, Update)

View File

@ -84,8 +84,7 @@ class FlowHandler(config_entries.ConfigFlow):
KEY_SCAN_INTERVAL: self._scan_interval.seconds,
KEY_SESSION: session,
})
else:
errors['base'] = 'auth_error'
errors['base'] = 'auth_error'
try:
with async_timeout.timeout(10):

View File

@ -130,7 +130,7 @@ class WebSocketHandler:
if msg.type in (WSMsgType.CLOSE, WSMsgType.CLOSING):
raise Disconnect
elif msg.type != WSMsgType.TEXT:
if msg.type != WSMsgType.TEXT:
disconnect_warn = 'Received non-Text message.'
raise Disconnect

View File

@ -75,8 +75,8 @@ class AreaRegistry:
if self._async_is_registered(name):
raise ValueError('Name is already in use')
else:
changes['name'] = name
changes['name'] = name
new = self.areas[area_id] = attr.evolve(old, **changes)
self.async_schedule_save()

View File

@ -293,7 +293,7 @@ def time_period_str(value: str) -> timedelta:
"""Validate and transform time offset."""
if isinstance(value, int):
raise vol.Invalid('Make sure you wrap time values in quotes')
elif not isinstance(value, str):
if not isinstance(value, str):
raise vol.Invalid(TIME_PERIOD_ERROR.format(value))
negative_offset = False
@ -440,7 +440,7 @@ def template(value):
"""Validate a jinja2 template."""
if value is None:
raise vol.Invalid('template value is None')
elif isinstance(value, (list, dict, template_helper.Template)):
if isinstance(value, (list, dict, template_helper.Template)):
raise vol.Invalid('template value should be a string')
value = template_helper.Template(str(value))

View File

@ -28,11 +28,10 @@ def generate_entity_id(entity_id_format: str, name: Optional[str],
if current_ids is None:
if hass is None:
raise ValueError("Missing required parameter currentids or hass")
else:
return run_callback_threadsafe(
hass.loop, async_generate_entity_id, entity_id_format, name,
current_ids, hass
).result()
return run_callback_threadsafe(
hass.loop, async_generate_entity_id, entity_id_format, name,
current_ids, hass
).result()
name = (slugify(name) or slugify(DEVICE_DEFAULT_NAME)).lower()

View File

@ -334,9 +334,9 @@ class EntityPlatform:
if not valid_entity_id(entity.entity_id):
raise HomeAssistantError(
'Invalid entity id: {}'.format(entity.entity_id))
elif (entity.entity_id in self.entities or
entity.entity_id in self.hass.states.async_entity_ids(
self.domain)):
if (entity.entity_id in self.entities or
entity.entity_id in self.hass.states.async_entity_ids(
self.domain)):
msg = 'Entity id already exists: {}'.format(entity.entity_id)
if entity.unique_id is not None:
msg += '. Platform {} does not generate unique IDs'.format(

View File

@ -8,7 +8,7 @@ flake8==3.7.7
mock-open==1.3.1
mypy==0.670
pydocstyle==3.0.0
pylint==2.2.2
pylint==2.3.0
pytest-aiohttp==0.3.0
pytest-cov==2.6.1
pytest-sugar==0.9.2

View File

@ -9,7 +9,7 @@ flake8==3.7.7
mock-open==1.3.1
mypy==0.670
pydocstyle==3.0.0
pylint==2.2.2
pylint==2.3.0
pytest-aiohttp==0.3.0
pytest-cov==2.6.1
pytest-sugar==0.9.2