Skip to content

Pillow cannot be loaded in python optimize (2) mode #3231

Description

@Menollo

What did you do?

I was loading the PIL module with 'import PIL' when running Python with PYTHONOPTIMZE=2 (or python -OO).

What did you expect to happen?

I Expected the PIL/Pillow Library to be imported.

What actually happened?

I received an exception:
AttributeError: 'NoneType' object has no attribute 'format'

What versions of Pillow and Python are you using?

Pillow 5.2.0 / Python 3.6.5

Reason:

PYTHONOPTIMIZE=2 / python -OO strips the _ _ doc _ _ variable.

Example:

create a file called test.py with only import PIL

import PIL

Execute it with python in optimize mode

python -OO test.py

You will receive the following exception:

Traceback (most recent call last):
  File "test.py", line 1, in <module>
    import PIL
  File "/usr/lib/python3.6/site-packages/PIL/__init__.py", line 27, in <module>
    __doc__ = __doc__.format(__version__)  # include version in docstring
AttributeError: 'NoneType' object has no attribute 'format'

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugAny unexpected behavior, until confirmed feature.

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions