import fnmatch
import logging
import re
-from typing import Any, Callable, List, Optional, Set
+from typing import Any, Callable, List, Optional, Set, Sequence
# This module is commonly used by others in here and should avoid
# taking any unnecessary dependencies back on them.
"""An ACL that allows or denies by applying predicates."""
def __init__(self,
*,
- allow_predicate_list: List[Callable[[Any], bool]] = None,
- deny_predicate_list: List[Callable[[Any], bool]] = None,
+ allow_predicate_list: Sequence[Callable[[Any], bool]] = None,
+ deny_predicate_list: Sequence[Callable[[Any], bool]] = None,
order_to_check_allow_deny: Order,
default_answer: bool) -> None:
super().__init__(
"""Main program should call this early in main()"""
global config_parse_called
if config_parse_called:
- return
+ return config
config_parse_called = True
global saved_messages
unit: str) -> None:
self.name = name
self.category = category
- self.to_canonical = to_canonical
- self.from_canonical = from_canonical
+ self.to_canonical_f = to_canonical
+ self.from_canonical_f = from_canonical
self.unit = unit
def to_canonical(self, n: Number) -> Number:
- return self.to_canonical(n)
+ return self.to_canonical_f(n)
def from_canonical(self, n: Number) -> Number:
- return self.from_canonical(n)
+ return self.from_canonical_f(n)
def unit_suffix(self) -> str:
return self.unit
def convert(magnitude: Number,
from_thing: str,
- to_thing: str) -> Number:
+ to_thing: str) -> float:
src = conversion_catalog.get(from_thing, None)
dst = conversion_catalog.get(to_thing, None)
if src is None or dst is None:
def _convert(magnitude: Number,
from_unit: Converter,
- to_unit: Converter) -> Number:
+ to_unit: Converter) -> float:
canonical = from_unit.to_canonical(magnitude)
converted = to_unit.from_canonical(canonical)
- return converted
+ return float(converted)
def sec_to_min(s: float) -> float:
@classmethod
def is_valid(cls, value: Any):
if type(value) is int:
- print("int")
return value in cls._value2member_map_
elif type(value) is TimeUnit:
- print("TimeUnit")
return value.value in cls._value2member_map_
elif type(value) is str:
- print("str")
return value in cls._member_names_
else:
print(type(value))
def coalesce(
inputs: Iterator[Dict[Any, Any]],
*,
- aggregation_function: Callable[[Any, Any, Any], Any] = coalesce_by_creating_list
+ aggregation_function: Callable[[Any, Any], Any] = coalesce_by_creating_list
) -> Dict[Any, Any]:
- out = {}
+ out: Dict[Any, Any] = {}
for d in inputs:
for key in d:
if key in out:
converter = datetime.datetime.fromtimestamp
def formatTime(self, record, datefmt=None):
- ct = self.converter(record.created, pytz.timezone("US/Pacific"))
+ ct = MillisecondAwareFormatter.converter(
+ record.created, pytz.timezone("US/Pacific")
+ )
if datefmt:
s = ct.strftime(datefmt)
else:
return in_str
-def add_thousands_separator(in_str: str, *, separator_char = ',', places = 3) -> str:
+def add_thousands_separator(
+ in_str: str,
+ *,
+ separator_char = ',',
+ places = 3
+) -> str:
if isinstance(in_str, int):
in_str = f'{in_str}'
-
if is_number(in_str):
return _add_thousands_separator(
in_str,
@decorator_utils.timed
def driver() -> None:
results = {}
- for _ in range(200):
+ for _ in range(50):
n = random.randint(0, 100000)
results[n] = list_primes(n)
tot = 0
#!/bin/bash
for test in $(ls *_test.py); do
- echo "------------------------------ ${test} ------------------------------"
+ echo "------------------------- ${test} -------------------------"
${test}
done