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).

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/", line 13, in <module> class Font(_Font): File "/usr/lib64/python3.3/site-packages/pygame/", line 26, in Font __unull = as_unicode(r"\x00") File "/usr/lib64/python3.3/site-packages/pygame/", 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 is fixed, Python 3.3 fails 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 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. Log in to comment