-2

I have a circular dependency, how can I fix this?

LogClass

... import ErrorClass

    def log(self, error):
      # isinstance(error, ErrorClass)

ErrorClass

... import LogClass

    log = LogClass()
el_pup_le
  • 11,711
  • 26
  • 85
  • 142
  • 1
    Possible duplicate of [Circular dependency in Python](https://stackoverflow.com/questions/894864/circular-dependency-in-python) – HariUserX Jun 30 '18 at 06:04
  • Are you actually getting an error? What is it? Which module do you import in your program to trigger it? – Mad Physicist Jun 30 '18 at 06:12

1 Answers1

0

The ErrorClass should not be aware of the log class, hence there shouldn't be an import in it. You can add a method to the LogClass:

def log_error(error):
    # isinstance(error, ErrorClass)
    log.error(...)  # if log is a python logger
Omri Levi
  • 177
  • 5