Skip to content

[BUG] Style.clear_meta_and_links should reset hash #2942

@rodrigogiraoserrao

Description

@rodrigogiraoserrao

The hash of a Style instance depends on _meta and _link:

rich/rich/style.py

Lines 432 to 445 in 6d30ad0

def __hash__(self) -> int:
if self._hash is not None:
return self._hash
self._hash = hash(
(
self._color,
self._bgcolor,
self._attributes,
self._set_attributes,
self._link,
self._meta,
)
)
return self._hash

So, when the link and meta are cleared with the method Style.clear_meta_and_links, the cached hash should be cleared:

rich/rich/style.py

Lines 664 to 668 in 6d30ad0

style._link = None
style._link_id = ""
style._hash = self._hash
style._null = False
style._meta = None

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions