Add __slots__ to internal parser types

Dynamic properties are not used by these types, so using __slots__ is
slightly more efficient. Public inherited properties are also included.
This commit is contained in:
Jeremy Saklad 2021-09-18 17:41:17 -05:00
parent 21ea715dd1
commit 50625cdc27
Signed by: Jeremy Saklad
GPG Key ID: 9CA2149583EDBF84
4 changed files with 9 additions and 0 deletions

View File

@ -18,6 +18,8 @@ def convert_to_enum(value):
return enum[split[1]]
class BlacklistAction(argparse.Action):
__slots__ = '_nargs', 'option_strings', 'dest', 'nargs', 'const', 'default', 'type', 'choices', 'required', 'help', 'metavar'
def __init__(self, **kwargs):
nargs = kwargs.get('nargs')

View File

@ -5,5 +5,8 @@ from argparse import ArgumentParser
class BoneMarketArgumentParser(ArgumentParser):
"""An ArgumentParser with the ability to read files with any number of space-delimited arguments on a line."""
__slots__ = 'description', 'argument_default', 'prefix_chars', 'conflict_handler', 'prog', 'usage', 'epilog', 'formatter_class', 'fromfile_prefix_chars', 'add_help', 'allow_abbrev', 'exit_on_error'
def convert_arg_line_to_args(self, arg_line):
return arg_line.split()

View File

@ -4,6 +4,8 @@ __author__ = "Jeremy Saklad"
import argparse
class EnumAction(argparse.Action):
__slots__ = '_enum', '_nargs', 'option_strings', 'dest', 'nargs', 'const', 'default', 'type', 'choices', 'required', 'help', 'metavar'
def __init__(self, **kwargs):
# Pop off the type value
enum = kwargs.pop('type', None)

View File

@ -15,6 +15,8 @@ from ..data.torsos import Torso
class ListAction(argparse.Action):
"""Lists enumerations referenced by provided strings then exits"""
__slots__ = '_nargs', '_default', 'option_strings', 'dest', 'nargs', 'const', 'default', 'type', 'choices', 'required', 'help', 'metavar'
list_options = [enum.__name__.lower() for enum in [
Torso,
Skull,