Add check_untyped_defs (#15510)

* Add check_untyped_defs

* Change to regular if-else
This commit is contained in:
Andrey authored and Paulus Schoutsen committed 2018-07-18 00:28:44 +02:00
1 parent 7d7c2104ea
commit 24d2261060
15 files changed
+70 -44

No files matched your search

+5 -4
View File
@@ -13,7 +13,8 @@ from functools import wraps
from types import MappingProxyType
from unicodedata import normalize
from typing import Any, Optional, TypeVar, Callable, KeysView, Union, Iterable
from typing import (Any, Optional, TypeVar, Callable, KeysView, Union, # noqa
Iterable, List, Mapping)
from .dt import as_local, utcnow
@@ -150,9 +151,9 @@ class OrderedSet(MutableSet):
def __init__(self, iterable=None):
"""Initialize the set."""
self.end = end = []
end += [None, end, end] # sentinel node for doubly linked list
self.map = {} # key --> [key, prev, next]
self.end = end = [] # type: List[Any]
end += [None, end, end] # sentinel node for doubly linked list
self.map = {} # type: Mapping[List, Any] # key --> [key, prev, next]
if iterable is not None:
self |= iterable
+10 -4
View File
@@ -65,8 +65,14 @@ def _chain_future(source, destination):
if not isinstance(destination, (Future, concurrent.futures.Future)):
raise TypeError('A future is required for destination argument')
# pylint: disable=protected-access
source_loop = source._loop if isinstance(source, Future) else None
dest_loop = destination._loop if isinstance(destination, Future) else None
if isinstance(source, Future):
source_loop = source._loop # type: ignore
else:
source_loop = None
if isinstance(destination, Future):
dest_loop = destination._loop # type: ignore
else:
dest_loop = None
def _set_state(future, other):
if isinstance(future, Future):
@@ -102,7 +108,7 @@ def run_coroutine_threadsafe(coro, loop):
if not coroutines.iscoroutine(coro):
raise TypeError('A coroutine object is required')
future = concurrent.futures.Future()
future = concurrent.futures.Future() # type: concurrent.futures.Future
def callback():
"""Handle the call to the coroutine."""
@@ -150,7 +156,7 @@ def run_callback_threadsafe(loop, callback, *args):
if ident is not None and ident == threading.get_ident():
raise RuntimeError('Cannot be called from within the event loop')
future = concurrent.futures.Future()
future = concurrent.futures.Future() # type: concurrent.futures.Future
def run_callback():
"""Run callback and store result."""
+8 -2
View File
@@ -49,12 +49,18 @@ def detect_location_info():
return LocationInfo(**data)
def distance(lat1, lon1, lat2, lon2):
def distance(lat1: Optional[float], lon1: Optional[float],
lat2: float, lon2: float) -> Optional[float]:
"""Calculate the distance in meters between two points.
Async friendly.
"""
return vincenty((lat1, lon1), (lat2, lon2)) * 1000
if lat1 is None or lon1 is None:
return None
result = vincenty((lat1, lon1), (lat2, lon2))
if result is None:
return None
return result * 1000
def elevation(latitude, longitude):
+1 -1
View File
@@ -29,7 +29,7 @@ class AsyncHandler(object):
"""Initialize async logging handler wrapper."""
self.handler = handler
self.loop = loop
self._queue = asyncio.Queue(loop=loop)
self._queue = asyncio.Queue(loop=loop) # type: asyncio.Queue
self._thread = threading.Thread(target=self._process)
# Delegate from handler
+2 -1
View File
@@ -1,6 +1,7 @@
"""Unit system helper class and methods."""
import logging
from typing import Optional
from numbers import Number
from homeassistant.const import (
@@ -99,7 +100,7 @@ class UnitSystem(object):
return temperature_util.convert(temperature,
from_unit, self.temperature_unit)
def length(self, length: float, from_unit: str) -> float:
def length(self, length: Optional[float], from_unit: str) -> float:
"""Convert the given length to this unit system."""
if not isinstance(length, Number):
raise TypeError('{} is not a numeric value.'.format(str(length)))
+1 -1
View File
@@ -311,7 +311,7 @@ yaml.SafeLoader.add_constructor('!include_dir_merge_named',
# pylint: disable=redefined-outer-name
def represent_odict(dump, tag, mapping, flow_style=None):
"""Like BaseRepresenter.represent_mapping but does not issue the sort()."""
value = []
value = [] # type: list
node = yaml.MappingNode(tag, value, flow_style=flow_style)
if dump.alias_key is not None:
dump.represented_objects[dump.alias_key] = node