From 50625cdc272d6de8b27e97585c114ea9cee70a00 Mon Sep 17 00:00:00 2001 From: Jeremy Saklad Date: Sat, 18 Sep 2021 17:41:17 -0500 Subject: [PATCH] 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. --- bonemarketsolver/objects/blacklistaction.py | 2 ++ bonemarketsolver/objects/bonemarketargumentparser.py | 3 +++ bonemarketsolver/objects/enumaction.py | 2 ++ bonemarketsolver/objects/listaction.py | 2 ++ 4 files changed, 9 insertions(+) diff --git a/bonemarketsolver/objects/blacklistaction.py b/bonemarketsolver/objects/blacklistaction.py index 1ddf842..b5ba2c2 100644 --- a/bonemarketsolver/objects/blacklistaction.py +++ b/bonemarketsolver/objects/blacklistaction.py @@ -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') diff --git a/bonemarketsolver/objects/bonemarketargumentparser.py b/bonemarketsolver/objects/bonemarketargumentparser.py index 196b196..3d52094 100644 --- a/bonemarketsolver/objects/bonemarketargumentparser.py +++ b/bonemarketsolver/objects/bonemarketargumentparser.py @@ -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() diff --git a/bonemarketsolver/objects/enumaction.py b/bonemarketsolver/objects/enumaction.py index 9b162bd..607d635 100644 --- a/bonemarketsolver/objects/enumaction.py +++ b/bonemarketsolver/objects/enumaction.py @@ -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) diff --git a/bonemarketsolver/objects/listaction.py b/bonemarketsolver/objects/listaction.py index 41a7ec1..722669c 100644 --- a/bonemarketsolver/objects/listaction.py +++ b/bonemarketsolver/objects/listaction.py @@ -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,