Skip to content

gplugins.gmeep's per-file submodules share a name with the function they export #758

Description

@Alisama20

Repo/version: gplugins 2.0.1 on gdsfactory 9.34.2

What happened: Every submodule under gplugins/gmeep/ (write_sparameters_meep.py, write_sparameters_grating.py, ...) is named identically to the one function it exports, and gplugins/gmeep/__init__.py re-exports that function into the package namespace. The result is that import gplugins.gmeep.write_sparameters_grating as _wsg does not reliably bind _wsg to the module — it can bind to the function of the same name instead.

Steps to reproduce:

import gplugins.gmeep.write_sparameters_grating as _wsg

# This fails when _wsg is the function, not the module:
_wsg.get_simulation_grating_fiber = my_patched_version
# AttributeError: 'function' object has no attribute 'get_simulation_grating_fiber'

Expected: import gplugins.gmeep.write_sparameters_grating as _wsg should bind _wsg to the module object, so module-level names can be patched or inspected.

Actual: The import binds to the re-exported function. The only reliable way to reach the module object is to index sys.modules directly by the dotted string:

import sys
wsg = sys.modules["gplugins.gmeep.write_sparameters_grating"]

This workaround is undocumented anywhere in the library; the failure mode is a plain AttributeError with no hint that the import has bound to the wrong object.

Suggested fix: Either rename the re-exported function or the submodule so they do not collide, or document the collision and the sys.modules[...] workaround in the contributor documentation for anyone patching gmeep's internals.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions