progress on pylint in lbry/conf.py
This commit is contained in:
parent
28fbb70858
commit
731b29ce91
1 changed files with 27 additions and 26 deletions
53
lbry/conf.py
53
lbry/conf.py
|
@ -3,9 +3,10 @@ import re
|
||||||
import sys
|
import sys
|
||||||
import typing
|
import typing
|
||||||
import logging
|
import logging
|
||||||
import yaml
|
|
||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
|
|
||||||
|
import yaml
|
||||||
from appdirs import user_data_dir, user_config_dir
|
from appdirs import user_data_dir, user_config_dir
|
||||||
from lbry.error import InvalidCurrencyError
|
from lbry.error import InvalidCurrencyError
|
||||||
from lbry.dht import constants
|
from lbry.dht import constants
|
||||||
|
@ -14,7 +15,7 @@ from lbry.wallet.coinselection import STRATEGIES
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
NOT_SET = type('NOT_SET', (object,), {})
|
NOT_SET = type('NOT_SET', (object,), {}) # pylint: disable=invalid-name
|
||||||
T = typing.TypeVar('T')
|
T = typing.TypeVar('T')
|
||||||
|
|
||||||
CURRENCIES = {
|
CURRENCIES = {
|
||||||
|
@ -35,7 +36,7 @@ class Setting(typing.Generic[T]):
|
||||||
self.metavar = metavar
|
self.metavar = metavar
|
||||||
|
|
||||||
def __set_name__(self, owner, name):
|
def __set_name__(self, owner, name):
|
||||||
self.name = name
|
self.name = name # pylint: disable=attribute-defined-outside-init
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def cli_name(self):
|
def cli_name(self):
|
||||||
|
@ -63,13 +64,13 @@ class Setting(typing.Generic[T]):
|
||||||
for location in obj.modify_order:
|
for location in obj.modify_order:
|
||||||
location[self.name] = val
|
location[self.name] = val
|
||||||
|
|
||||||
def validate(self, val):
|
def validate(self, value):
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
def deserialize(self, value):
|
def deserialize(self, value): # pylint: disable=no-self-use
|
||||||
return value
|
return value
|
||||||
|
|
||||||
def serialize(self, value):
|
def serialize(self, value): # pylint: disable=no-self-use
|
||||||
return value
|
return value
|
||||||
|
|
||||||
def contribute_to_argparse(self, parser: ArgumentParser):
|
def contribute_to_argparse(self, parser: ArgumentParser):
|
||||||
|
@ -82,14 +83,14 @@ class Setting(typing.Generic[T]):
|
||||||
|
|
||||||
|
|
||||||
class String(Setting[str]):
|
class String(Setting[str]):
|
||||||
def validate(self, val):
|
def validate(self, value):
|
||||||
assert isinstance(val, str), \
|
assert isinstance(value, str), \
|
||||||
f"Setting '{self.name}' must be a string."
|
f"Setting '{self.name}' must be a string."
|
||||||
|
|
||||||
|
|
||||||
class Integer(Setting[int]):
|
class Integer(Setting[int]):
|
||||||
def validate(self, val):
|
def validate(self, value):
|
||||||
assert isinstance(val, int), \
|
assert isinstance(value, int), \
|
||||||
f"Setting '{self.name}' must be an integer."
|
f"Setting '{self.name}' must be an integer."
|
||||||
|
|
||||||
def deserialize(self, value):
|
def deserialize(self, value):
|
||||||
|
@ -97,8 +98,8 @@ class Integer(Setting[int]):
|
||||||
|
|
||||||
|
|
||||||
class Float(Setting[float]):
|
class Float(Setting[float]):
|
||||||
def validate(self, val):
|
def validate(self, value):
|
||||||
assert isinstance(val, float), \
|
assert isinstance(value, float), \
|
||||||
f"Setting '{self.name}' must be a decimal."
|
f"Setting '{self.name}' must be a decimal."
|
||||||
|
|
||||||
def deserialize(self, value):
|
def deserialize(self, value):
|
||||||
|
@ -106,8 +107,8 @@ class Float(Setting[float]):
|
||||||
|
|
||||||
|
|
||||||
class Toggle(Setting[bool]):
|
class Toggle(Setting[bool]):
|
||||||
def validate(self, val):
|
def validate(self, value):
|
||||||
assert isinstance(val, bool), \
|
assert isinstance(value, bool), \
|
||||||
f"Setting '{self.name}' must be a true/false value."
|
f"Setting '{self.name}' must be a true/false value."
|
||||||
|
|
||||||
def contribute_to_argparse(self, parser: ArgumentParser):
|
def contribute_to_argparse(self, parser: ArgumentParser):
|
||||||
|
@ -127,7 +128,7 @@ class Toggle(Setting[bool]):
|
||||||
|
|
||||||
|
|
||||||
class Path(String):
|
class Path(String):
|
||||||
def __init__(self, doc: str, default: str = '', *args, **kwargs):
|
def __init__(self, doc: str, *args, default: str = '', **kwargs):
|
||||||
super().__init__(doc, default, *args, **kwargs)
|
super().__init__(doc, default, *args, **kwargs)
|
||||||
|
|
||||||
def __get__(self, obj, owner):
|
def __get__(self, obj, owner):
|
||||||
|
@ -204,16 +205,16 @@ class StringChoice(String):
|
||||||
raise ValueError(f"Default value must be one of: {', '.join(valid_values)}")
|
raise ValueError(f"Default value must be one of: {', '.join(valid_values)}")
|
||||||
self.valid_values = valid_values
|
self.valid_values = valid_values
|
||||||
|
|
||||||
def validate(self, val):
|
def validate(self, value):
|
||||||
super().validate(val)
|
super().validate(value)
|
||||||
if val not in self.valid_values:
|
if value not in self.valid_values:
|
||||||
raise ValueError(f"Setting '{self.name}' value must be one of: {', '.join(self.valid_values)}")
|
raise ValueError(f"Setting '{self.name}' value must be one of: {', '.join(self.valid_values)}")
|
||||||
|
|
||||||
|
|
||||||
class ListSetting(Setting[list]):
|
class ListSetting(Setting[list]):
|
||||||
|
|
||||||
def validate(self, val):
|
def validate(self, value):
|
||||||
assert isinstance(val, (tuple, list)), \
|
assert isinstance(value, (tuple, list)), \
|
||||||
f"Setting '{self.name}' must be a tuple or list."
|
f"Setting '{self.name}' must be a tuple or list."
|
||||||
|
|
||||||
def contribute_to_argparse(self, parser: ArgumentParser):
|
def contribute_to_argparse(self, parser: ArgumentParser):
|
||||||
|
@ -226,10 +227,10 @@ class ListSetting(Setting[list]):
|
||||||
|
|
||||||
class Servers(ListSetting):
|
class Servers(ListSetting):
|
||||||
|
|
||||||
def validate(self, val):
|
def validate(self, value):
|
||||||
assert isinstance(val, (tuple, list)), \
|
assert isinstance(value, (tuple, list)), \
|
||||||
f"Setting '{self.name}' must be a tuple or list of servers."
|
f"Setting '{self.name}' must be a tuple or list of servers."
|
||||||
for idx, server in enumerate(val):
|
for idx, server in enumerate(value):
|
||||||
assert isinstance(server, (tuple, list)) and len(server) == 2, \
|
assert isinstance(server, (tuple, list)) and len(server) == 2, \
|
||||||
f"Server defined '{server}' at index {idx} in setting " \
|
f"Server defined '{server}' at index {idx} in setting " \
|
||||||
f"'{self.name}' must be a tuple or list of two items."
|
f"'{self.name}' must be a tuple or list of two items."
|
||||||
|
@ -260,10 +261,10 @@ class Servers(ListSetting):
|
||||||
|
|
||||||
class Strings(ListSetting):
|
class Strings(ListSetting):
|
||||||
|
|
||||||
def validate(self, val):
|
def validate(self, value):
|
||||||
assert isinstance(val, (tuple, list)), \
|
assert isinstance(value, (tuple, list)), \
|
||||||
f"Setting '{self.name}' must be a tuple or list of strings."
|
f"Setting '{self.name}' must be a tuple or list of strings."
|
||||||
for idx, string in enumerate(val):
|
for idx, string in enumerate(value):
|
||||||
assert isinstance(string, str), \
|
assert isinstance(string, str), \
|
||||||
f"Value of '{string}' at index {idx} in setting " \
|
f"Value of '{string}' at index {idx} in setting " \
|
||||||
f"'{self.name}' must be a string."
|
f"'{self.name}' must be a string."
|
||||||
|
|
Loading…
Reference in a new issue