Replies: 4 comments 6 replies
-
def requires_project(wrapped):
@functools.wraps(wrapped)
def wrapper(*args, **kwargs):
if not env.project:
raise RuntimeError()
return wrapped(*args, **kwargs, project=env.project)
class C:
@requires_project
def my_method(self, arg1, arg2, *, project: Project):
return project |
Beta Was this translation helpful? Give feedback.
-
I think we should try and make it possible to initialise all objects without globals like env.project or env.shareable_project existing? |
Beta Was this translation helpful? Give feedback.
-
The project could also explicitly be passed in the constructor? Rather than sneaking it via the back door. Only thing then is instances then look after their own reference to the project. If the project is subsequently changed (... which it shouldn't be!) then that reference is stale and harder to keep track of. |
Beta Was this translation helpful? Give feedback.
-
To look after caches we can do this: class _Env:
def __init__(...):
self.caches = []
def create_cache(self):
cache = dict()
self.caches.append(cache)
return cache Should make life a lot easier to keep track of all these caches. |
Beta Was this translation helpful? Give feedback.
-
The use of a global state is very useful to Cassini.
env.project
andenv.o
are needed for the jl_gui and magics to work.It is also very useful for extensions to do things.
However! It does create a lot of problems.
It's quite a pain that, for example, essentially, Tier objects are invalid unless a Project instance has been created, but we rely on constantly checking this within Tier methods, which has a major code smell.
Furthermore, this makes testing a challenge, because we have to initialise a new project every time we want to test methods of a Tier instance.
Beta Was this translation helpful? Give feedback.
All reactions