summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcello Stanisci <stanisci.m@gmail.com>2017-12-07 15:22:12 +0100
committerMarcello Stanisci <stanisci.m@gmail.com>2017-12-07 15:22:12 +0100
commitb2ea43b7ccba2f5dd191185f7eb86edff69d9137 (patch)
treebad1affb8304cb0e926fe344e1e370aabe3b4db9
parent4efff7788f052cfdd2949af9198eb2c18a4cd4e8 (diff)
downloadbank-b2ea43b7ccba2f5dd191185f7eb86edff69d9137.tar.gz
bank-b2ea43b7ccba2f5dd191185f7eb86edff69d9137.tar.bz2
bank-b2ea43b7ccba2f5dd191185f7eb86edff69d9137.zip
resolving conflict between mypy and Python itself
-rw-r--r--talerbank/app/amount.py8
-rw-r--r--talerbank/talerconfig.py57
2 files changed, 33 insertions, 32 deletions
diff --git a/talerbank/app/amount.py b/talerbank/app/amount.py
index 45e306e..c3e2b93 100644
--- a/talerbank/app/amount.py
+++ b/talerbank/app/amount.py
@@ -62,7 +62,7 @@ class Amount:
# Parse a string matching the format "A:B.C"
# instantiating an amount object.
@classmethod
- def parse(cls: Type[Amount], amount_str: str) -> Amount:
+ def parse(cls, amount_str: str):
exp = r'^\s*([-_*A-Za-z0-9]+):([0-9]+)\.([0-9]+)\s*$'
import re
parsed = re.search(exp, amount_str)
@@ -79,7 +79,7 @@ class Amount:
# 0 if a == b
# 1 if a > b
@staticmethod
- def cmp(am1: Amount, am2: Amount) -> int:
+ def cmp(am1, am2) -> int:
if am1.currency != am2.currency:
raise CurrencyMismatch(am1.currency, am2.currency)
if am1.value == am2.value:
@@ -98,7 +98,7 @@ class Amount:
self.fraction = fraction
# Add the given amount to this one
- def add(self, amount: Amount) -> None:
+ def add(self, amount) -> None:
if self.currency != amount.currency:
raise CurrencyMismatch(self.currency, amount.currency)
self.value += amount.value
@@ -106,7 +106,7 @@ class Amount:
self.__normalize()
# Subtract passed amount from this one
- def subtract(self, amount: Amount) -> None:
+ def subtract(self, amount) -> None:
if self.currency != amount.currency:
raise CurrencyMismatch(self.currency, amount.currency)
if self.fraction < amount.fraction:
diff --git a/talerbank/talerconfig.py b/talerbank/talerconfig.py
index 41ebf44..5d42adc 100644
--- a/talerbank/talerconfig.py
+++ b/talerbank/talerconfig.py
@@ -93,33 +93,8 @@ def expand(var: str, getter: Callable[[str], str]) -> str:
return result + var[pos:]
-class OptionDict(collections.defaultdict):
- def __init__(self, config: SectionDict, section_name: str) -> None:
- self.config = weakref.ref(config)
- self.section_name = section_name
- super().__init__()
- def __missing__(self, key: str) -> Entry:
- entry = Entry(self.config(), self.section_name, key)
- self[key] = entry
- return entry
- def __getitem__(self, chunk: str) -> Entry:
- return super().__getitem__(chunk.lower())
- def __setitem__(self, chunk: str, value: Entry) -> None:
- super().__setitem__(chunk.lower(), value)
-
-
-class SectionDict(collections.defaultdict):
- def __missing__(self, key):
- value = OptionDict(self, key)
- self[key] = value
- return value
- def __getitem__(self, chunk: str) -> OptionDict:
- return super().__getitem__(chunk.lower())
- def __setitem__(self, chunk: str, value: OptionDict) -> None:
- super().__setitem__(chunk.lower(), value)
-
class Entry:
- def __init__(self, config: SectionDict, section: str, option: str, **kwargs) -> None:
+ def __init__(self, config, section: str, option: str, **kwargs) -> None:
self.value = kwargs.get("value")
self.filename = kwargs.get("filename")
self.lineno = kwargs.get("lineno")
@@ -180,6 +155,32 @@ class Entry:
return "%s:%s" % (self.filename, self.lineno)
+class OptionDict(collections.defaultdict):
+ def __init__(self, config, section_name: str) -> None:
+ self.config = weakref.ref(config)
+ self.section_name = section_name
+ super().__init__()
+ def __missing__(self, key: str) -> Entry:
+ entry = Entry(self.config(), self.section_name, key)
+ self[key] = entry
+ return entry
+ def __getitem__(self, chunk: str) -> Entry:
+ return super().__getitem__(chunk.lower())
+ def __setitem__(self, chunk: str, value: Entry) -> None:
+ super().__setitem__(chunk.lower(), value)
+
+
+class SectionDict(collections.defaultdict):
+ def __missing__(self, key):
+ value = OptionDict(self, key)
+ self[key] = value
+ return value
+ def __getitem__(self, chunk: str) -> OptionDict:
+ return super().__getitem__(chunk.lower())
+ def __setitem__(self, chunk: str, value: OptionDict) -> None:
+ super().__setitem__(chunk.lower(), value)
+
+
class TalerConfig:
"""
One loaded taler configuration, including base configuration
@@ -194,7 +195,7 @@ class TalerConfig:
# defaults != config file: the first is the 'base'
# whereas the second overrides things from the first.
@staticmethod
- def from_file(filename=None, load_defaults=True) -> TalerConfig:
+ def from_file(filename=None, load_defaults=True):
cfg = TalerConfig()
if filename is None:
xdg = os.environ.get("XDG_CONFIG_HOME")
@@ -237,7 +238,7 @@ class TalerConfig:
LOGGER.warning("no base directory found")
@staticmethod
- def from_env(*args, **kwargs) -> TalerConfig:
+ def from_env(*args, **kwargs):
"""
Load configuration from environment variable TALER_CONFIG_FILE
or from default location if the variable is not set.