Skip to content

Reenable relative imports#83

Merged
da-h merged 3 commits intomasterfrom
reenable_relative_imports
Nov 9, 2021
Merged

Reenable relative imports#83
da-h merged 3 commits intomasterfrom
reenable_relative_imports

Conversation

@da-h
Copy link
Copy Markdown
Owner

@da-h da-h commented Nov 9, 2021

Reenable relative imports in Module Repository

This MR fixes #81, where importing an enum from two different modules resulted in seperate instances of the same definition.

Description

Setup:
To check this, this MR adds a unit test, where an enum is imported (relative import) by another module.

Problem:

  • Previously, this lead to errors. Reason for this behavior is that each module is interpreted gets "sandboxed" into a seperate parent-module with a random id. Using a relative import circumvents this mechanism.
  • On the contrary, sandboxing modules is required when handling either with multiple miniflask-instances (as done for unit-testing) or modules of the same name in different module repositories on the filesystem. In both cases, we have to handle how to distinguish modules with the same local id.

New Behavior:

  • The solution is to sandbox each miniflask-instance instead of each module.
  • This enables relative imports in between modules and repositories, using the repository-ids given upon repository registration (i.e. using dict-registration).
  • The new behavior requires __init__.py files to be present for the whole relative-import path. This is in comply with typical relative imports in python.

Check all before creating this PR:

  • unit tests adapted / created

@da-h da-h requested a review from sbrodehl November 9, 2021 17:07
@da-h da-h merged commit 4fc2c4b into master Nov 9, 2021
@da-h da-h deleted the reenable_relative_imports branch November 9, 2021 18:42
@da-h da-h mentioned this pull request Nov 10, 2021
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Using Enums of other Modules is buggy

2 participants