da-h/miniflask

`set_scope()` with relative paths

sbrodehl opened this issue · 1 comments

Hi all,

I am currently implementing multiple variants of a module which all work in the same scope.
Therefore, I use mf.set_scope("."). Which kind of bugs me.

Here is the module layout:

modules/
    ABC/defaults/__init__.py
    .../  ...   /.module
    ABC/variant1/__init__.py
    .../  ...   /.module
    ABC/variant2/__init__.py
    .../  ...   /.module

The module ABC has some default settings in defaults and two variants, namely variant1 and variant2.
Setting mf.set_scope(".") works fine, and they lived happily ever after.

But setting the scope to "." implies to me that we use the current directory/module as scope, which is either ABC/defaults, ABC/variant1 or ABC/variant2. Thus the mf.set_scope(".") command seems IMHO to be pointless.
Instead, I expected to set the scope to "..", which usually translates to the parent directory/module.
And this makes sense, since the module_id before set_scope is e.g. ABC.variant1, thus the parent is ABC.

What is the design choice behind using "." vs. ".."?

da-h commented

The design choice of letting a variant (e.g. variant1) to behave internally like (redefine_scope) or share the variables of (set_scope) of another another module comes from the idea that submodules relate to modules like skript-files to folders.
As ./ in a skript does reference the folder the skript is called in . references . the module directory a module is defined in.

I understand the misunderstanding related the set_scope functionality and to be honest I was unsure about the specification of the method.
Overall, I think you are right that specifying the identity using . is more natural.