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

Three small fixes for panphon on Windows and Python 3.12 #59

Closed
wants to merge 2 commits into from

Conversation

joanise
Copy link

@joanise joanise commented Aug 23, 2024

Three small fixes for panphon on Windows and Python 3.12:

  1. On Python 3.12, I was getting infinite recursion in featuretable.py because sort_segments() used self.segments which called segments() and thus sort_segments() again. Using the underlying self._segments instead in sort_segments() removes the infinite recursion.

  2. Also in featuretable.py, with open(fn) as f: on line 79 assumes utf-8 on Linux, but it assumes cp-1252 on my Windows machine. Declaring the encoding explicitly fixed the problem. For code portability, it's unfortunately and very annoyingly required to always declare the encoding when opening a file in text mode in Python.

    There are other places in the code where text-mode open statements don't declare the encoding. I'm not sure why those did not cause problems in my tests.

  3. Minor warning from Python 3.12: in the docstring, the \ in \w has to be escaped so that help(Segments) get printed correctly.

I have tested these changes with python 3.8 and python 3.12 on a machine with Windows 10, using python -m unittest panphon/test/test* to run all unit tests.

I discovered these problems while testing #57 on my machine. Note that this PR includes the commit from #57 because without it I could not test on Python 3.8.

roedoejet and others added 2 commits August 9, 2024 13:42
in python 3.8 you cannot subscript the collections.abc.Mapping class so importing from typing is more stable across python versions

see https://stackoverflow.com/questions/59955751/abcmeta-object-is-not-subscriptable-when-trying-to-annotate-a-hash-variable
1) On Python 3.12, I was getting infinite recursion in featuretable.py
   because sort_segments() used self.segments which called segments()
   and thus sort_segments() again. Using the underlying self._segments
   instead in sort_segments() removes the infinite recursion.

2) Also in featuretable.py, `with open(fn) as f:` on line 79 assumes
   utf-8 on Linux, but it assumes cp-1252 on my Windows machine.
   Declaring the encoding explicitly fixed the problem.
   For code portability, it's unfortunately and very annoyingly required
   to always declare the encoding when opening a file in text mode in
   Python.

   There are other places in the code where text-mode open statements
   don't declare the encoding. I'm not sure why those did not cause
   problems in my tests.

3) Minor warning from Python 3.12: in the docstring, the \ in \w has to
   be escaped so that `help(Segments)` get printed correctly.
@joanise
Copy link
Author

joanise commented Aug 23, 2024

Hum, oops, I see #56 already fixes things on Windows, and more thoroughly than I did. With #56, this PR is irrelevant. Please consider merging #56 and #57 and releasing a patch so we can use panphon 0.21(.3?) in our projects.

@joanise
Copy link
Author

joanise commented Sep 10, 2024

Closing this in favour of the much better solution in #56

@joanise joanise closed this Sep 10, 2024
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.

2 participants