Skip to content

Commit

Permalink
use deepcopy on dicts to avoid changing default options
Browse files Browse the repository at this point in the history
  • Loading branch information
ravachol-yang committed Mar 30, 2024
1 parent 53f375b commit 916b2a2
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 7 deletions.
2 changes: 0 additions & 2 deletions app/models/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ class Audio(Base):
"n":{"enabled": False}
}

_options = dict(OPTIONS_DEFAULT)

# generate a noise sample
@staticmethod
def noise_sample():
Expand Down
6 changes: 3 additions & 3 deletions app/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
base.py
the Base model
"""
import copy

from telebot import TeleBot
from telebot.types import Message
Expand All @@ -11,13 +12,12 @@ class Base:
OPTIONS_AVAILABLE = []
OPTIONS_DEFAULT = {}

_options = dict(OPTIONS_DEFAULT)

def __init__(self,
bot:TeleBot = None,
message:Message = None):
self.__bot = bot
self.__message = message
self._options = copy.deepcopy(self.OPTIONS_DEFAULT)


# get content of this object
Expand All @@ -33,7 +33,7 @@ def set_options(self, options):
if options["bool_options"]:
opt = options["options"]
# index for mapping from boolean array to options
index = 0
index = 0
for i in self._options:
# change options accordingly, opt with be chopped to the last elements
self._options[i]["enabled"] = opt[-len(self.OPTIONS_AVAILABLE):][index]
Expand Down
2 changes: 0 additions & 2 deletions app/models/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ class Text(Base):
"content": string.digits}
}

_options = dict(OPTIONS_DEFAULT)

# generate random string, returns the object itself
def generate(self, options = None):
# check options
Expand Down

0 comments on commit 916b2a2

Please sign in to comment.