Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support python 3.6 #241

Closed
gjvc opened this issue Aug 30, 2020 · 6 comments
Closed

Support python 3.6 #241

gjvc opened this issue Aug 30, 2020 · 6 comments

Comments

@gjvc
Copy link

gjvc commented Aug 30, 2020

I would like to be able to use xsdata with pypy. I can't right now, because pypy does not work with lxml. I see that you are making an effort to use less lxml. If you have a completely lxml-free version, I would be very happy to test it for you :-)

@tefra
Copy link
Owner

tefra commented Aug 30, 2020

Awesome @gjvc I think there a few more steps to have a completely lxml-free version, but I think I got the parser working with the native xml.sax.handler.ContentHandler see #240

The codegen tool is still using the default handler which is lxml, if you have managed to generate the models through another venv or if you are using custom models give it a try and let me know what you thin.

from xsdata.formats.dataclass.parsers import XmlParser
from xsdata.formats.dataclass.parsers.handlers import SaxHandler

parser = XmlParser(handler=SaxHandler)  # Native python 
p.parse("some/file.xml", Books)

I haven't checked xsdata with pypy, does lxml fail on the setup or during usage?

@gjvc
Copy link
Author

gjvc commented Aug 31, 2020

Well. Good and bad news. It's late here, so I'm sorry if this is not crystal clear.

I'm using pypy3 on Debian bullseye/sid. Looks like lxml and pypy3 are actually playing well with each other at installation/wheel build time and runtime, so please forget my comment above -- looks like the historic problems have been resolved. (Google for lxml and pypy3 to see the sort of problems people used to encounter.)

Note that the latest cpython-equivalent version of pypy3 is "Python 3.6.9". This is not Python 3.7, so I have had to install the dataclasses module from https://pypi.org/project/dataclasses/ using pip. But, when I use version 0.7 of dataclasses I get lots of these warnings from xsdata:

warning: Unassigned parsed object ElementName

where "ElementName" is a legitimate element name as per the grammar. I also get a lot of "object is not iterable" errrors with python 3.6 and dataclasses 0.7. (I was using python3.8 originally, with no problems.) This suggests there is a difference between the behaviours of dataclasses 0.7 from pypi and dataclasses from cpython 3.8.

I'm a bit stuck right now with all this yak-shaving. I might see if there is an early 3.7 version of pypy I can use.

The next thing to do is to test cpython 3.6, xsdata, and dataclasses 0.7 from pypi. I see from the front page of xsdata that you only support python 3.7 onwards. pypy is only at 3.6 right now, so bringing this issue back on-topic (finally), this problem reduces to xsdata supporting python 3.6 via dataclasses 0.7 from pypi (which you may not have any interest in doing, which is of course your prerogative :-))

whew.

@tefra
Copy link
Owner

tefra commented Aug 31, 2020

There is an issue with the typing module and bool type for some reason, that's why I never officially added support for python3.6.

See pr #242

tefra added a commit that referenced this issue Aug 31, 2020
tefra added a commit that referenced this issue Aug 31, 2020
@tefra tefra changed the title pypy compatibility Support python 3.6 Aug 31, 2020
@gjvc
Copy link
Author

gjvc commented Sep 1, 2020

This looks good. I will test some more and report back. Thanks once again :-)

@tefra
Copy link
Owner

tefra commented Sep 1, 2020

Well it has a drawback you can not use typing.Union safely because of the 3.6 issue.

I am not sure how to proceed here I definitely don't want to offer a monkey patch...
I would rather add a notice for py36 users or something.

tefra added a commit that referenced this issue Sep 1, 2020
Notes:
In py36 the typing module is flattening baseclasses in
unions eg Union[int, bool] -> (int), there is no official
workaround but from all my samples I 've only encountered this case
in a few tests cases in the w3c test suite.
tefra added a commit that referenced this issue Sep 1, 2020
Notes:
In py36 the typing module is flattening baseclasses in
unions eg Union[int, bool] -> (int), there is no official
workaround but from all my samples I 've only encountered this case
in a few tests cases in the w3c test suite.
@tefra tefra closed this as completed in e85f03b Sep 1, 2020
@gjvc
Copy link
Author

gjvc commented Sep 2, 2020

Thank you very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants