Skip to content

Commit

Permalink
MNT: Fix double evaluation of _LazyTickList
Browse files Browse the repository at this point in the history
Closes matplotlib#28908.

The final instance.majorTicks list must be assigned after running
`_get_tick()` because that may call `reset_ticks()`, which invalidates
a previous set list. We still temporarily assign an empty tick list
to instance.majorTicks, because `_get_tick()` may rely on that
attibute to exist.
  • Loading branch information
timhoffm committed Sep 30, 2024
1 parent 6404c95 commit 017118e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
Empty file.
10 changes: 6 additions & 4 deletions lib/matplotlib/axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,17 +538,19 @@ def __get__(self, instance, owner):
# instance._get_tick() can itself try to access the majorTicks
# attribute (e.g. in certain projection classes which override
# e.g. get_xaxis_text1_transform). In order to avoid infinite
# recursion, first set the majorTicks on the instance to an empty
# list, then create the tick and append it.
# recursion, first set the majorTicks on the instance temporarily
# to an empty lis. Then create the tick; note that _get_tick()
# may call reset_ticks(). Therefore, the final tick list is
# created and assigned afterwards.
if self._major:
instance.majorTicks = []
tick = instance._get_tick(major=True)
instance.majorTicks.append(tick)
instance.majorTicks = [tick]
return instance.majorTicks
else:
instance.minorTicks = []
tick = instance._get_tick(major=False)
instance.minorTicks.append(tick)
instance.minorTicks = [tick]
return instance.minorTicks


Expand Down

0 comments on commit 017118e

Please sign in to comment.