Skip to content

Conversation

@chrisrink10
Copy link
Member

@chrisrink10 chrisrink10 commented Sep 4, 2024

Fixes #1060

@chrisrink10 chrisrink10 force-pushed the feature/reload-ns branch 2 times, most recently from 74ca790 to 60c1c5c Compare September 8, 2024 19:33
@chrisrink10 chrisrink10 marked this pull request as ready for review September 18, 2024 19:34
Comment on lines +389 to +393
if (cached := self._cache.get(fullname)) is None:
spec = module.__spec__
assert spec is not None, "Module must have a spec"
cached = {"spec": spec}
self._cache[spec.name] = cached
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I doubt this ever happens except in testing, but I was finding that calling monkeypatch.syspath_prepend that monkeypatch calls importlib.invalidate_caches() which was causing issues trying to access values from the cache without any guard. Now we just reconstruct the cache from the module if that does happen.

ns_sym = sym.symbol(ns_name)
ns = self.get(ns_sym)
assert ns is not None, "Namespace must exist after being required"
self.add_alias(ns, ns_sym)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it was always my intent to add the fully-qualified name as an alias to the namespace, but it never mattered before now.

@chrisrink10 chrisrink10 merged commit d002d1a into main Sep 18, 2024
12 checks passed
@chrisrink10 chrisrink10 deleted the feature/reload-ns branch September 18, 2024 19:50
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.

Add the ability to reload namespaces

1 participant