Refactor: introduce state object#264
Conversation
|
As I was previously commenting, I don't particularly like this |
|
OK, now I see there is more. Let me think about that. Thanks! |
|
While I like the idea of moving the two monkey-patch functions to a different module, I don't think that this |
|
just so i understand, before coming up with another approach: are you mostly concerned about about the callsites (ie the if so, how about this pattern instead: from mocket.state import Mocket
def some_function() -> None:
Mocket.register()by just doing the following in Mocket = MocketState()? |
|
Let's split into two different aspects:
|
Let me rephrase it: finding a class called |
|
i think I just stepped into the age-old trap of singleton patterns in python. https://discuss.python.org/t/any-extra-reason-to-not-use-classes-for-singletons/19243/5 where there are two options:
you seem to prefer option2, for understandable reasons, while i prefer option 1. I'll try to apply option2 :) |
|
Honestly: I am not sure I would write it this way today. We did it in 2013 and I don't see any strong reason to change it today. |
|
yeah. i also rarely use singletons. |
|
The thing here is: we don't need to instantiate Mocket more than once, expecting we always get back the same instance. So, it's not even used as a Singleton, it's just a class implementing some methods, it's pure syntactic sugar. |
refactor: Mocket - add typing and get rid of cyclic import
5833f65 to
6291c31
Compare
|
|
ok it's back to a singleton-class, with the injection-logic extracted. i had to change one import |
I really appreciate your patience. :) |
|
of course. you're the maintainer, I'm just a guy. opensource lives from open, friendly and respectful collaboration :) |



continuation of #261 and #263
This PR does two things:
This is done to prevent cyclic-imports.