Skip to content

Incorrect documentation for ImagePalette size parameter (and maybe not needed at all) #5636

@rjmorris

Description

@rjmorris

The documentation for the ImagePalette initializer in version 8.3.1 says the palette parameter must be "of length size times the number of colors in mode". Therefore, for an RGB image, I would expect len(palette) == size * 3. However, the code asserts that len(palette) == size, so I believe the code and documentation are inconsistent. (The same problem existed in 8.2.0 before some ImagePalette improvements were made, so this wasn't introduced with that change.)

Furthermore, it isn't clear to me that the size parameter is needed at all. It isn't stored on self, and the only place it's used in the initializer is to assert that its value is 0 or len(palette), so it doesn't seem to provide any benefit. The only reason to keep it that I can think of is to maintain backwards compatibility with existing code that explicitly passes the parameter.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions