You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would like to create a way to explicitly suppress a specific implicit export.
Pitch
I am working with a wrapper library that attempts to unify an interface between multiple backends. So for example it does something like this:
# my_lib/foo.py
from . import BACKEND_A, BACKEND_B
if BACKEND_A:
from lib_a.foo import *
Confabulator.bar = Confabulator.baz
elif BACKEND_B:
from lib_b.foo import *
The implicit export via star-import here is helpful because there are a lot of classes to import, more may be added, and most of them don't need to be modified like this at all.
Unfortunately this causes some minor problems with typing - I get an attr-defined error depending on the installed backend:
from my_lib.foo import Confabulator
c = Confabulator()
reveal_type(c) # revealed type is lib_a.foo.Confabulator
c.bar() # raises an [attr-defined] error
At first I thought this was an issue with adding class attributes after definition (rejected in #5363), but it's also a problem if I try to instead to subclass and re-assign. I think the implicit re-export is getting in the way of redefining the class.
My initial thought on how to achieve this would be to allow from lib_a.foo import Confabulator as _Confabulatorafter the from lib_a.foo import * to kind of undo the implicit export. I poked around in the code a bit but have not figured out the best way to do this yet. I do worry this would be a breaking change, however. I am open to any other suggestions or workarounds!
The text was updated successfully, but these errors were encountered:
Feature
I would like to create a way to explicitly suppress a specific implicit export.
Pitch
I am working with a wrapper library that attempts to unify an interface between multiple backends. So for example it does something like this:
The implicit export via star-import here is helpful because there are a lot of classes to import, more may be added, and most of them don't need to be modified like this at all.
Unfortunately this causes some minor problems with typing - I get an
attr-defined
error depending on the installed backend:At first I thought this was an issue with adding class attributes after definition (rejected in #5363), but it's also a problem if I try to instead to subclass and re-assign. I think the implicit re-export is getting in the way of redefining the class.
My initial thought on how to achieve this would be to allow
from lib_a.foo import Confabulator as _Confabulator
after thefrom lib_a.foo import *
to kind of undo the implicit export. I poked around in the code a bit but have not figured out the best way to do this yet. I do worry this would be a breaking change, however. I am open to any other suggestions or workarounds!The text was updated successfully, but these errors were encountered: