1212
TypeError: RGBColor.__new__() crashes when parsing RGBA colors · Issue #53 · dfop02/html4docx · GitHub
Skip to content

TypeError: RGBColor.__new__() crashes when parsing RGBA colors #53

@BreathBlush

Description

@BreathBlush

I encountered a TypeError when the library attempts to process styles containing RGBA colors (e.g., rgba(0, 0, 0, 0.65)). The utils.parse_color function appears to return a tuple of 4 values (r, g, b, a), but the RGBColor class is currently defined to only accept r, g, b.

When RGBColor(*colors) is called with a 4-item tuple, it passes 5 arguments to __new__ (cls, r, g, b, a), resulting in a crash because the method signature only expects 4 arguments (cls, r, g, b).

Exception: TypeError('RGBColor.__new__() takes 4 positional arguments but 5 were given')

Steps to Reproduce

  1. Parse HTML/content containing a CSS style with an alpha channel, for example: color: rgba(0, 0, 0, 0.65);.

  2. The utils.parse_color returns a 4-tuple.

  3. The code executes self.run.font.color.rgb = RGBColor(*colors).

  4. The application crashes.

Proposed Solution

Modify RGBColor.__new__ to accept variable arguments (*_) so that it can gracefully handle and ignore the Alpha channel (or any extra arguments) while still strictly enforcing the RGB integers.

Image

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions