Closed elisbyberi closed 1 year ago
The xpath
library makes use of the Element
object type in various places when processing the instructions, though the type doesn't have to be explicitly defined within the functions perhaps? The Element
object then uses the xpath
library in its find
, findall
, finditer
, and gettext
methods. example:
https://github.com/imgurbot12/codon-xml/blob/master/xml/xpath/functions.py#L23 and
https://github.com/imgurbot12/codon-xml/blob/master/xml/etree.py#L181
Right now serialize_xml
references the "Special" element types which are define below to determine how to write the data and then called in ElementTree
though everything can be restructured to theoretically avoid this issue. We can place the element definitions in their own element.codon
file and then leave ElementTree
with serialize_xml
in it's own etree.codon
file:
https://github.com/imgurbot12/codon-xml/blob/master/xml/etree.py#L67
https://github.com/imgurbot12/codon-xml/blob/master/xml/etree.py#L192
https://github.com/imgurbot12/codon-xml/blob/master/xml/etree.py#L247
Similar importing to the serialize_xml
instance also exist with the Parser
and TreeBuilder
types which get referenced with the ElementTree
type. All of these can theoretically be fixed by moving the Element
object types to their own file so I guess I'll do that now. The xpath
thing seems to be the only major issue that I know of at the moment.
did my best to resolve the importing issues according to what you said in the codon issue. https://github.com/imgurbot12/codon-xml/commit/2f1dda0f3ae7a19821d41cfb9dd104d362adc7cb
I am currently testing a scenario that involves demo classes, which is similar to the issue at hand.
I have successfully tested this MRE in Codon. Please let me know if I have demonstrated the problematic logic correctly. Note that from . import xpath
doesn't work.
# xpath/__init__.py
from ..element import Element
def find(elem: Element, xpath) -> Optional[Element]: # Self == Element
"""
find first matching element associated w/ xpath
:param elem: root element to search xpath from
:param xpath: raw xpath expression
:return: first element found matching criteria
"""
print(xpath, elem)
# element.py
class Element:
def find(self, path) -> Optional[Element]: # Self == Element
from xpath import find # `from . import xpath` doesn't work
return find(self, path)
def __repr__(self):
return 'This is class Element.'
e = Element()
e.find('Find!')
That looks like it will work. yup! Thanks.
It needs just a little work, but excessive caution to solve compatibility issues. Then, we can test the library in both Python and Codon at the same time.
Closing due to inactivity. Feel free to reopen if you have any questions or issues!
Which modules are susceptible to circular importing and require special handling to avoid errors?