Open hoodmane opened 9 months ago
Let's start with the simpler issue, importing a mixin. We can detect that WindowOrWorkerGlobalScope
is a mixin from the webidl. A mixin is not a concrete interface so it does not exist like a concrete interface (like Window).
A simple solution could be to rename the mixin with a starting _ (e.g., _WindowOrWorkerGlobalScope
) so it will still be part of the type hierarchy.
This will not prevent importing it but it will be a good signal that it is not to be imported. At this moment I have no other ideas.
A quick comment about
from js import indexedDB
This is valid because window is a global scope and window has a property called indexDB. I did some quick and dirty to have something working here
Probably the correct thing to do is to detect all the global objects (are there others than window?) and copy all the properties of its corresponding type (Window) at the root of the pyi.
What do you think?
Any feedback on this or the previous comment are welcome!
A simple solution could be to rename the mixin with a starting _
This seems to be the officially recommended approach: https://typing.readthedocs.io/en/latest/source/stubs.html#private-definitions
Actually I think the better approach is to make a _types.py
file with a __all__
field listing all the public stuff and then in __init__.py
do:
from ._types import *
This works the way we want: https://typing.readthedocs.io/en/latest/source/stubs.html#imports
In
__init__.py
we see stuff like:So this typechecks but raises an
ImportError
at runtime:And this is a type error but works at runtime: