Closed FredHappyface closed 3 years ago
Can you explain what you're trying to do here? Is your intent to pass a module to the init routine of Widgets
? Or are you supposed to pass a class within that module? If the method accepts any module, you should probably annotate it with object
because a module in itself isn't really a type in the Python type system. Arguably, Pylance should flag it as an error if you try to use a module within a type annotation.
Yeah, the module is passed to init
This is so the user gets to select which pysimplegui module they want to use and these (essentially) have the same signatures so I wanted to pass through a type where pylance would not flag every method and class that is a member of the pysimplegui module (which using object would do)
Not sure what the best workaround would be in my case. But it is intended that the module is passed to the class (this then has functions that spit out various widgets)
This is an unusual (and I would claim a bad) interface. Classes should be used in cases like this, not modules.
From a type checking perspective, there aren't any great options here. Modules don't have "signatures", and one module cannot be assigned to another. The best workaround I can think of is to annotate it with object
or Any
. Annotating it with a module won't work.
It probably wasn't the best design decision to be honest though I'm pretty sure that's the only way I can interact with that particular module. Using Any probably is the best call in my case.
Thank you for your time on this :)
Environment data
Expected behaviour
No type error is detected as the types are equal
Actual behaviour
Logs
Code Snippet / Additional information