In Python, I am dynamically creating a namespace by modifying globals()
.
For some background, I'm masking/filtering another file to get rid of some unwanted members and wrap foreign functions with a mutex. The masked file contains auto-generated bindings for a relatively large C library that is not thread-compatible.
However, this confuses VS code syntax highlighting and auto-completion: the wrapper file's members, which are added dynamically on import time, are not recognized, and the namespace is seen as empty.
As a workaround, I thought about filtering the original namespace in place rather than masking it, but would prefer to preserve it as-is so we can still access the unmodified namespace if desired. Also, this way the IDE's namespace info would still be incorrect: dynamic changes would not be taken into account and excluded members would still be shown.
As a last resort, supposedly I could write some code to generate a PEP 484 stub file (.pyi
), but don't like the idea of another dynamic file that is effectively unnecessary if only the IDE were smarter.
Is there an option to make VS code agnostic of globals()
, or any other workaround to make it recognize the dynamic members?