Flask Webcast #3: Circular Dependencies

Posted by
on under

In this live webcast I explain how to prevent circular dependency errors in Python. Most of this presentation is a live coding session in which I refactor a single-file Flask application into a fully fleshed out structure with multiple packages and modules, demonstrating how I completely avoid circular dependencies.

Become a Patron!

Hello, and thank you for visiting my blog! If you enjoyed this article, please consider supporting my work on this blog on Patreon!

  • #1 Haris said

    How are you testing this with tox flake8?
    Can you explain it a little when and how it is used for testing dependancies, and whether I can use it on my Windows as well?

  • #2 Miguel Grinberg said

    @Haris: I don't have a copy of the configuration that I used in this video, but I don't use it for anything specifically related to circular dependencies, just to make sure that after I do some refactoring work there are no obvious mistakes. And yes, this works on Windows as well.

  • #3 margrami said

    Hola Miguel,
    Congratulations, your blog is really a reference about Flask. Thank you for sharing.

  • #4 Lucas Baião Pires said

    In my opinion, this still is circular dependency. The program works just because you are making the imports in different lines, but this should not happen. There should be a more elegant solution for this. Other languages, such as C#, TypeScript, Java, etc, do not present such problems, and do not resort to such poor solutions. I just hate that I cannot find a work around this!

  • #5 Miguel Grinberg said

    @Lucas: the workaround is to organize your files so that circular references aren't necessary. It is possible, but a lot more work.

Leave a Comment