mercredi 22 septembre 2021

How to handle an increasing number of operations in a python class

I'm trying to improve my code design skills but not sure what to do. Currently I have a class that needs to set certain keys on init and it looks something like this:

class A:
  def __init__(self):
    try:
      key1 = some_key_finder("key1")
      key2 = some_key_finder("key2")
      key3 = some_key_finder("key3")
    except KeyError as err:
      raise SecretNotFoundError(f"...{err}")

Initially it only set one key but as the reqs changed I had to set two more keys. My question is: how to make the above code more scalable and handle an (hypothetically) increasing number of keys?

Aucun commentaire:

Enregistrer un commentaire