Skip to content

756: support for / test with python 3.13#768

Merged
lognaturel merged 3 commits intoXLSForm:masterfrom
lindsay-stevens:pyxform-756
Jun 6, 2025
Merged

756: support for / test with python 3.13#768
lognaturel merged 3 commits intoXLSForm:masterfrom
lindsay-stevens:pyxform-756

Conversation

@lindsay-stevens
Copy link
Copy Markdown
Contributor

@lindsay-stevens lindsay-stevens commented Jun 3, 2025

Closes #756

Why is this the best possible solution? Were any other approaches considered?

To align with pyodk python version support. According to the python website, 3.14 is due out 2025-10 and 3.10 goes EOL 2026-10.

What are the regression risks?

The XML escaping algo changed in python 3.13 to what seems to be a more correct way (referring to normalization rules in the XML spec) - namely, to escape \r\n\t in attribute values. So pyxform now does that too, for all supported python versions. Pyxform already was overriding some escaping behaviour, because prior to python 3.13 double quotes were escaped in element text but they only need to be escaped in attributes. Unfortunately python implemented the change in a non-backwards compatible way, by adding a new required attr argument, with no default, to the _write_data func that pyxform was using. In any case pyxform would have needed to do something to maintain compatibility with 3.10 through 3.13 since the new output is different.

The regression risk then is perhaps tab or newlines characters might have some kind of impact on Collect/Webforms/Enketo behaviour e.g. if they were normalised out before and now will be preserved due to escaping, or if any of the form clients don't recognise the escape codes and suddenly users see the escape codes instead of whitespace or nothing. There is the workaround for users to remove these characters from the XLSForm but generally pyxform tries to smooth over friction points like that. If these regression scenarios are a concern we could do some testing to check, and/or not escape \r\n\t in attributes in pyxform, or not emit \r\n\t values in attributes, etc.

The dev dependency update to formencode drops support for python 3.7 and 3.8 but that should not affect users. Could be an issue for library users but it's difficult to avoid since the update is required for python 3.13 compatibility. The alternative is to remove this dev dependency, but that would require refactoring all of the remaining "old style" tests that use formencode for XML document comparison.

Does this change require updates to documentation? If so, please file an issue here and include the link below.

Updated readme.

Before submitting this PR, please make sure you have:

  • included test cases for core behavior and edge cases in tests
  • run python -m unittest and verified all tests pass
  • run ruff format pyxform tests and ruff check pyxform tests to lint code
  • verified that any code or assets from external sources are properly credited in comments

lognaturel
lognaturel previously approved these changes Jun 3, 2025
@lognaturel lognaturel dismissed their stale review June 3, 2025 16:59

Whoops, tests aren't passing yet

@lindsay-stevens
Copy link
Copy Markdown
Contributor Author

@lognaturel Yeah hoping this would be a quick one but it looks like some standard library changes - minidom API and cgi deprecated, maybe some other stuff.

- formencode==2.1.1 supports py3.9 to py3.13
- in py3.13, minidom was updated to only escape " in attributes, which
  is what pyxform has been doing for a while. It also now escapes \r\n\t
  in attributes, which pyxform was not doing, but appears to be the
  right behaviour according to the XML spec and related python tickets,
  so now pyxform does that for all supported versions.
Copy link
Copy Markdown
Contributor

@lognaturel lognaturel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Breaking Python 3.7 and 3.8 feels like no problem.

I really doubt tabs and newlines are common in attributes. The only context in which I think they could make sense is in constraint and required messages. Let’s go with this and if there are any issues we will learn something.

@lognaturel lognaturel merged commit 3fd6538 into XLSForm:master Jun 6, 2025
13 checks passed
@lognaturel lognaturel mentioned this pull request Jun 11, 2025
4 tasks
@lindsay-stevens lindsay-stevens deleted the pyxform-756 branch June 11, 2025 04:44
@lognaturel
Copy link
Copy Markdown
Contributor

I was wrong! Some users do use newlines in calculations and constraints for readability. I should have thought of that because I do it too. Those aren't typically a problem but there seem to be cases in which they crash Enketo: #771

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

Successfully merging this pull request may close these issues.

Add Python 3.13 to tests and supported versions

2 participants