Incompatibility with Python 3.3

Issue #146 resolved
Arfrever Frehtes Taifersar Arahesis created an issue

Python 3.3 has restored u"..." literals for str objects (unicode in Python 2). http://www.python.org/dev/peps/pep-0414/

This change broke pygame.compat.as_bytes() and pygame.compat.as_unicode(). I suggest 'if sys.version_info[0] < 3' check instead of try/except.

{{{ $ python3.2 -c 'import pygame.ftfont' $ python3.3 -c 'import pygame.ftfont' Traceback (most recent call last): File "<string>", line 1, in <module> File "/usr/lib64/python3.3/site-packages/pygame/ftfont.py", line 13, in <module> class Font(_Font): File "/usr/lib64/python3.3/site-packages/pygame/ftfont.py", line 26, in Font __unull = as_unicode(r"\x00") File "/usr/lib64/python3.3/site-packages/pygame/compat.py", line 87, in as_unicode return rstring.decode('unicode_escape', 'strict') AttributeError: 'str' object has no attribute 'decode' }}}

Comments (11)

  1. Lenard Lindstrom

    The intention is to check for a specific feature, not a particular release. Looking for the 'unicode' builtin, which is missing in Python 3.x, also works.

    As well, when compat.py is fixed, Python 3.3 fails ftfont_test.py with an 'RuntimeError: _freetype.Font instance is not initialized' raised in eight of the tests.

    There are also several modules with Python 3.x incompatibilities:

    • pygame.threads
    • pygame.examples.movieplayer
    • pygame._freetype
    • pygame.tests.test_utils.png

    These will included in this issue.

  2. Lenard Lindstrom

    For the ftfont_test.py failures, this happens when pygame.ftfont.Font is called with a file attribute of None. In this case pygame.pkgdata.getResource() is called within pygame._freetype.Font.__init__() to find the default font file, freesansbold.ttf. While doing so, getResource() looks for function __loader__. Guess what, Python issue 14646, implemented in Python 3.3, introduces a new __loader__ attribute to every module. This, apparently, is not the same "__loader__" getResource() expects, leading to the default font failing to loaded.

    A better understanding of pkgdata is needed before a solution can be found.

  3. Lenard Lindstrom

    With commit 7cec8bc and commit 73cefe4 Pygame 1.9.2 now passes, on gnu/linux the same unit tests for Python 3.3 as for Python 3.2 and Python 2.7. Alpha testing for Python 3.3 is now practical. This issue is closed.

  4. Log in to comment