ikamensh / flynt

A tool to automatically convert old string literal formatting to f-strings
MIT License
685 stars 33 forks source link

Get rid of global state #155

Closed akx closed 1 year ago

akx commented 1 year ago

This PR gets rid of modifying the state module wherever possible, in favor of a State dataclass. Wherever possible, I've tried to keep the low-level APIs state-less (pun intended), so should you need a single transform, you can do that without constructing a full State.

Additionally, itA future PR gets rid of modifying Chunks class-level state in favor of a LexerContext which is determined based on state.multiline.

ikamensh commented 1 year ago

I know first-hand that creating smaller PRs is more work; but it would help review and merge this work if you would decouple changes where possible. I see following components: 1) logging vs printing (please add examples of what new output looks like to a user) 2) Lexer state 3) global application state.

ikamensh commented 1 year ago

No intention to discourage. What benefits do you want to get out of this? Is it purely best practice motivated, or you've got something specific / practical in mind?

akx commented 1 year ago

No intention to discourage. What benefits do you want to get out of this? Is it purely best practice motivated, or you've got something specific / practical in mind?

Sure. Best practice motivated, and would make it easier to use flynt programmatically (or multi-thread/multi-process it for faster execution!). I can split this to multiple PRs, no worries :)

akx commented 1 year ago

I split the lexer bits into a future PR.