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
This library does a great job of typing the results from lxml functions. I can see, for example, that the XML parse method returns a type _ElementTree[_Element]. However, I cannot see a way to use these types in my own code. For example, I'd like to write a method which takes an ElementTree as an argument:
defmy_func(element: _ElementTree[_Element]):
pass
but I can't work out how to import these types. I tried:
fromtypes_lxmlimport_ElementTree, _Element
but this didn't work. So:
Is there a way to import these types to use in our own code?
from __future__ importannotationsfromlxml.etreeimport_ElementTree, _Elementdefmy_func(element: _ElementTree[_Element]):
pass
(2) automatically helps achieving (1) for you without your intervention, but you would need to remember adding __future__ to the very top of every file where it is used.
Could this be documented somewhere in the readme?
Yes, the documentation absolutely needs some love. I think I can get something done after clearing my current tasks at hand. I'll leave the report open for now as reminder.
Activity
abelcheung commentedon Apr 11, 2023
First things first, actually it is expected to only import classes from source, not from external stubs directly.
And there are a few ways to migitate the problem:
__future__:(2) automatically helps achieving (1) for you without your intervention, but you would need to remember adding
__future__to the very top of every file where it is used.Yes, the documentation absolutely needs some love. I think I can get something done after clearing my current tasks at hand. I'll leave the report open for now as reminder.
roblframpton commentedon Apr 11, 2023
Thanks a lot for your response, that has solved things for me.
abelcheung commentedon Apr 17, 2023
Doc now available on wiki.