2525
2626from __future__ import generator_stop
2727
28+ import abc
2829import getpass
2930import os .path
3031import re
3132
3233from sopel .tools import deprecated , get_input
3334
3435
35- class NO_DEFAULT ( object ) :
36+ class NO_DEFAULT :
3637 """A special value to indicate that there should be no default."""
3738
3839
39- class StaticSection ( object ) :
40+ class StaticSection :
4041 """A configuration section with parsed and validated settings.
4142
4243 This class is intended to be subclassed and customized with added
@@ -113,10 +114,7 @@ def configure_setting(self, name, prompt, default=NO_DEFAULT):
113114 setattr (self , name , value )
114115
115116
116- # TODO: Make this a proper abstract class when dropping Python 2 support.
117- # Abstract classes are much simpler to deal with once we only need to worry
118- # about Python 3.4 or newer. (https://stackoverflow.com/a/13646263/5991)
119- class BaseValidated (object ):
117+ class BaseValidated (abc .ABC ):
120118 """The base type for a setting descriptor in a :class:`StaticSection`.
121119
122120 :param str name: the attribute name to use in the config file
@@ -196,18 +194,13 @@ def configure(self, prompt, default, parent, section_name):
196194
197195 return self ._parse (value , parent , section )
198196
197+ @abc .abstractmethod
199198 def serialize (self , value , * args , ** kwargs ):
200- """Take some object, and return the string to be saved to the file.
201-
202- Must be implemented in subclasses.
203- """
204- raise NotImplementedError ("Serialize method must be implemented in subclass" )
199+ """Take some object, and return the string to be saved to the file."""
205200
201+ @abc .abstractmethod
206202 def parse (self , value , * args , ** kwargs ):
207- """Take a string from the file, and return the appropriate object.
208-
209- Must be implemented in subclasses."""
210- raise NotImplementedError ("Parse method must be implemented in subclass" )
203+ """Take a string from the file, and return the appropriate object."""
211204
212205 def __get__ (self , instance , owner = None ):
213206 if instance is None :
@@ -305,8 +298,7 @@ def __init__(self,
305298 serialize = None ,
306299 default = None ,
307300 is_secret = False ):
308- super (ValidatedAttribute , self ).__init__ (
309- name , default = default , is_secret = is_secret )
301+ super ().__init__ (name , default = default , is_secret = is_secret )
310302
311303 if parse == bool :
312304 parse , serialize = _deprecated_special_bool_handling (serialize )
@@ -334,7 +326,7 @@ def configure(self, prompt, default, parent, section_name):
334326 if self .parse == _parse_boolean :
335327 prompt += ' (y/n)'
336328 default = 'y' if default else 'n'
337- return super (ValidatedAttribute , self ).configure (prompt , default , parent , section_name )
329+ return super ().configure (prompt , default , parent , section_name )
338330
339331
340332class BooleanAttribute (BaseValidated ):
@@ -347,8 +339,7 @@ class BooleanAttribute(BaseValidated):
347339 If the ``default`` value is not specified, it will be ``False``.
348340 """
349341 def __init__ (self , name , default = False ):
350- super (BooleanAttribute , self ).__init__ (
351- name , default = default , is_secret = False )
342+ super ().__init__ (name , default = default , is_secret = False )
352343
353344 def configure (self , prompt , default , parent , section_name ):
354345 """Parse and return a value from user's input.
@@ -417,7 +408,7 @@ class SecretAttribute(ValidatedAttribute):
417408 otherwise behaves like other any option.
418409 """
419410 def __init__ (self , name , parse = None , serialize = None , default = None ):
420- super (SecretAttribute , self ).__init__ (
411+ super ().__init__ (
421412 name ,
422413 parse = parse ,
423414 serialize = serialize ,
@@ -498,7 +489,7 @@ class SpamSection(StaticSection):
498489
499490 def __init__ (self , name , strip = True , default = None ):
500491 default = default or []
501- super (ListAttribute , self ).__init__ (name , default = default )
492+ super ().__init__ (name , default = default )
502493 self .strip = strip
503494
504495 def parse (self , value ):
@@ -621,7 +612,7 @@ class ChoiceAttribute(BaseValidated):
621612 :type default: str
622613 """
623614 def __init__ (self , name , choices , default = None ):
624- super (ChoiceAttribute , self ).__init__ (name , default = default )
615+ super ().__init__ (name , default = default )
625616 self .choices = choices
626617
627618 def parse (self , value ):
@@ -668,7 +659,7 @@ class FilenameAttribute(BaseValidated):
668659 :type default: str
669660 """
670661 def __init__ (self , name , relative = True , directory = False , default = None ):
671- super (FilenameAttribute , self ).__init__ (name , default = default )
662+ super ().__init__ (name , default = default )
672663 self .relative = relative
673664 self .directory = directory
674665
0 commit comments