mistletoe icon indicating copy to clipboard operation
mistletoe copied to clipboard

Converted stateful global vars to context variables

Open edugonza opened this issue 6 months ago • 1 comments

I converted all stateful global vars to context variables that can be handled within contexts. Added an IsolatedContext context function that can be used to isolate context runs to prevent conflicts on the state of global variables.

I believe that this is a way to solve issues like #210 and #200 without refactoring the whole codebase. Even though a refactor to eliminate the usage of stateful global variables would be desirable.

edugonza avatar Jun 20 '25 07:06 edugonza

As the author of another globals-removing branch, I'd like to offer a few comments:

I first tried to make such a solution work myself, but couldn't get it to work transparently. Looking at your approach, it still needs some code changes (adding get()/set()), but probably fewer than my full refactor.

You actually found some global variables that I missed (thanks :) ), but you also missed some class-level variables, e.g. HtmlBlock._end_cond.

Since you're using contextvars, could you maybe use an explicit Context instead? Sadly it doesn't look very context manager friendly

dvdkon avatar Jul 16 '25 13:07 dvdkon