Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Style.clear_meta_and_links should reset hash #2942

Closed
rodrigogiraoserrao opened this issue Apr 28, 2023 · 2 comments · Fixed by #2943
Closed

[BUG] Style.clear_meta_and_links should reset hash #2942

rodrigogiraoserrao opened this issue Apr 28, 2023 · 2 comments · Fixed by #2943

Comments

@rodrigogiraoserrao
Copy link
Contributor

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

@github-actions
Copy link

Thank you for your issue. Give us a little time to review it.

PS. You might want to check the FAQ if you haven't done so already.

This is an automated reply, generated by FAQtory

Copy link

github-actions bot commented Jul 1, 2024

I hope we solved your problem.

If you like using Rich, you might also enjoy Textual

schneiderfelipe pushed a commit to schneiderfelipe/rich that referenced this issue Jul 16, 2024
* fix table rendering order of box elements

* Previously "mid" box elements appeared in last line of table
  (footer), while "footer" box elements appeared mid table body.
  Reversed that order so mid is truly mid, footer is truly footer.
* Tested with:

    ```
    table.box.head_left = '1'
    table.box.head_vertical = '2'
    table.box.head_right = '3'

    table.box.mid_left = '4'
    table.box.mid_vertical = '5'
    table.box.mid_right = '6'

    table.box.foot_left = '7'
    table.box.foot_vertical = '8'
    table.box.foot_right = '9'
    ```

  After change, correct ordering:

    ```
    +--------------------------------------------------------------------------+
    1Date        2Title                            2  Production2    Box Office3
    |------------ --------------------------------- ------------ --------------|
    4Dec 20, 20195Star Wars: The Rise of Skywalker 5$275,000,0005  $375,126,1186
    4May 25, 20185Solo: A Star Wars Story          5$275,000,0005  $393,151,3476
    7Dec 15, 20178Star Wars Ep. VIII: The Last Jedi8$262,000,0008$1,332,539,8899
    +--------------------------------------------------------------------------+
    ```

* added automated test

* improving test_box_substitute to cover more inputs of substitute()

* refactoring test_box_substitute: smaller and focused tests are better than large ones

* Update "logging.level.warning" to yellow"

* fix: fix get braces for `deque`

* test: add `test_deque` for `pretty_repr`

* docs(CHANGELOG): update CHANGELOG.md

* fix empty line print on jupyter

* add code_width in traceback

* Clear hashed cache when clearing meta.

Related issues: Textualize#2942

* Retroactively make CI happy.

* Fix release month for 13.4.0 & 13.4.1

* rm broken links from README

* add 'case_insensitive' option to Prompt

* add a test for the new prompt option

* update docs with new prompt option

* update CHANGELOG, CONTRIBUTORS

* fix typo in docs

* This corrects commit 3430909.

My Markdown formatter automatically changed the URL's in this to the more correct form
by wrapping them with '<' and '>', probably shouldn't force my style choices on another
project.

* Bump snok/install-poetry from 1.3.3 to 1.3.4

Bumps [snok/install-poetry](https://github.com/snok/install-poetry) from 1.3.3 to 1.3.4.
- [Release notes](https://github.com/snok/install-poetry/releases)
- [Commits](snok/install-poetry@v1.3.3...v1.3.4)

---
updated-dependencies:
- dependency-name: snok/install-poetry
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

* docstring supplement for Panel class

* hide_root arg in the Tree class

* VerticalCenter - added style arg

* used black tree.py

* added max_frames

!f

* Enable per-column enabling or disabling of highlighting

Defaults to the value of the self.table when the default value of None is unchanged.

It seems like the Column constructor didn't receive a `highlight` value, so I guess that it used to receive a highlight value at a later point. Someone who knows the project better could comment on that.

* refactor to 'case_sensitive' with default True

* use mypyc compiled black and update verison

* Add 'completed' parameter to 'track' function for resumable progress

This commit introduces a new 'completed' parameter to the 'track' function
in order to support resumable progress. Now users can specify the starting
point for progress, making it easier to implement progress resumption.

* Update progress.py

* Fix running tests in environment with FORCE_COLOR or NO_COLOR set

Ensure to unset FORCE_COLOR and NO_COLOR environment variables within
the scope of individual tests, in order to fix test failures when these
variables are set in the environment where tests are run, e.g. via:

    NO_COLOR=1 tox

* Skip tests failing with Python 3.13

* Bump github/codeql-action from 2 to 3

Bumps [github/codeql-action](https://github.com/github/codeql-action) from 2 to 3.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](github/codeql-action@v2...v3)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

* Improved file translation README.ru.md

- Typos have been fixed
- Fixed stylistic features of the translation

* Improved file translation README.ru.md

- Typos have been fixed
- Fixed stylistic errors of the translation

* Improved file translation README.ru.md

- Typos have been fixed
- Fixed stylistic errors of the translation

* Bump codecov/codecov-action from 3 to 4

Bumps [codecov/codecov-action](https://github.com/codecov/codecov-action) from 3 to 4.
- [Release notes](https://github.com/codecov/codecov-action/releases)
- [Changelog](https://github.com/codecov/codecov-action/blob/main/CHANGELOG.md)
- [Commits](codecov/codecov-action@v3...v4)

---
updated-dependencies:
- dependency-name: codecov/codecov-action
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

* Strip problematic private escape sequences:

["Private escape sequences"](https://en.wikipedia.org/wiki/ANSI_escape_code#Fp_Escape_sequences)
are escape sequences that are reserved for private use, though `\x1b7` and
`\x1b8` are commonly used for storing and restoring the current cursor
position. When those escape codes are not stripped the cursor jumps around and
causes Rich to write garbage output. An example of a program that uses this
cursor store/restore functionality is the APK package manager in Alpine Linux:

https://gitlab.alpinelinux.org/alpine/apk-tools/-/blob/48d91f482eb48a0a107b714ee183bb7e07782e14/src/print.c#L232-240

This commit updates the ANSI parser to ignore the `\x1b0`-`\x1b?` escape
sequences, thus preventing them from being printed and causing havoc.

* fix(syntax): include padding with background color override

* update changelog and contributors

* add test

* Drop a test that has not been used since it was committed

This test has been dead code since its introduction and does not get
executed by pytest due to starting with `text` rather than `test`. The
underlying data for this test is also non-trivial to update and
dependent on the specific Python version.

Since this is already dead code and is non-trivial to update, removing
this test more clearly reflects what happens with this dead code in
tests and prevents potential confusion due to its presence.

* Drop a constant that is not used anywhere

This is unused and thus can be removed.

* Update tree.py

* Update CONTRIBUTORS.md

* Update tree.py

* Update CHANGELOG.md

* feat: speedup import time using sys.platform

* fix changelog

* fix for panel title

* changelog

* changelog

* changelog

* test fix

* exit track thread

* changelog

* progress

* pyupgrade

* Bump ipywidgets from 8.1.1 to 8.1.3

Bumps [ipywidgets](https://github.com/jupyter-widgets/ipywidgets) from 8.1.1 to 8.1.3.
- [Release notes](https://github.com/jupyter-widgets/ipywidgets/releases)
- [Commits](jupyter-widgets/ipywidgets@8.1.1...8.1.3)

---
updated-dependencies:
- dependency-name: ipywidgets
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

* Bump sphinx-rtd-theme from 1.0.0 to 2.0.0

Bumps [sphinx-rtd-theme](https://github.com/readthedocs/sphinx_rtd_theme) from 1.0.0 to 2.0.0.
- [Changelog](https://github.com/readthedocs/sphinx_rtd_theme/blob/master/docs/changelog.rst)
- [Commits](readthedocs/sphinx_rtd_theme@1.0.0...2.0.0)

---
updated-dependencies:
- dependency-name: sphinx-rtd-theme
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

* Bump sphinx from 5.1.1 to 7.3.7

Bumps [sphinx](https://github.com/sphinx-doc/sphinx) from 5.1.1 to 7.3.7.
- [Release notes](https://github.com/sphinx-doc/sphinx/releases)
- [Changelog](https://github.com/sphinx-doc/sphinx/blob/master/CHANGES.rst)
- [Commits](sphinx-doc/sphinx@v5.1.1...v7.3.7)

---
updated-dependencies:
- dependency-name: sphinx
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

* changelog

* docstring

* docs

* highlight column

* format

* docs: rename OSX to macOS

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: Jonathan Eunice <jonathan@3playmedia.com>
Co-authored-by: Andre Hora <andrehoraa@gmail.com>
Co-authored-by: Alex <alexprengere@gmail.com>
Co-authored-by: Xuehai Pan <XuehaiPan@pku.edu.cn>
Co-authored-by: Ceyda Cinarel <15624271+cceyda@users.noreply.github.com>
Co-authored-by: 이창호 <ckdgh518@naver.com>
Co-authored-by: Rodrigo Girão Serrão <5621605+rodrigogiraoserrao@users.noreply.github.com>
Co-authored-by: Jason Novinger <jnovinger@gmail.com>
Co-authored-by: zach valenta <zjv5002@gmail.com>
Co-authored-by: Grant Ramsay <seapagan@gmail.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Jakub <77514091+Coderbeep@users.noreply.github.com>
Co-authored-by: Gene Myslinsky <47491689+GeneMyslinsky@users.noreply.github.com>
Co-authored-by: Jules Gagnon-Marchand <jgagnonmarchand@gmail.com>
Co-authored-by: Darren Burns <darrenb900@gmail.com>
Co-authored-by: Darren Burns <darrenburns@users.noreply.github.com>
Co-authored-by: alex-rakowski <alexrakowski90@gmail.com>
Co-authored-by: Haskely <Haskely@live.com>
Co-authored-by: Michał Górny <mgorny@gentoo.org>
Co-authored-by: Karolina Surma <ksurma@redhat.com>
Co-authored-by: askras <askrasnikov@gmail.com>
Co-authored-by: dosisod <39638017+dosisod@users.noreply.github.com>
Co-authored-by: TomJGooding <101601846+TomJGooding@users.noreply.github.com>
Co-authored-by: Pradyun Gedam <pradyunsg@users.noreply.github.com>
Co-authored-by: jdvanwijk <123641381+jdvanwijk@users.noreply.github.com>
Co-authored-by: J.P. Hutchins <jphutchins@gmail.com>
Co-authored-by: Will McGugan <willmcgugan@gmail.com>
Co-authored-by: Máté Gyöngyösi <gyongyosimate1@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant