Skip to content

Fix Timer._timer_count to increment the class variable, not instance#6385

Closed
bysiber wants to merge 1 commit intoTextualize:mainfrom
bysiber:fix/timer-class-counter
Closed

Fix Timer._timer_count to increment the class variable, not instance#6385
bysiber wants to merge 1 commit intoTextualize:mainfrom
bysiber:fix/timer-class-counter

Conversation

@bysiber
Copy link

@bysiber bysiber commented Feb 20, 2026

Summary

Fix Timer._timer_count to actually increment the class variable instead of creating a shadowing instance attribute.

Problem

class Timer:
    _timer_count: int = 1  # Class variable

    def __init__(self, ...):
        self.name = f"Timer#{self._timer_count}" if name is None else name
        self._timer_count += 1  # Bug: creates instance attribute, class var stays 1

In Python, self._timer_count += 1 reads the class variable (1), adds 1 (2), and stores the result as an instance attribute on self. The class variable Timer._timer_count is never modified — it stays at 1 forever.

Every auto-named timer gets the name "Timer#1".

Fix

Use Timer._timer_count += 1 (explicit class reference) to modify the class variable directly.

self._timer_count += 1 reads the class variable (1), adds 1, and
stores the result as an instance attribute. The class variable
stays at 1 forever, so every auto-named timer gets "Timer#1".

Use Timer._timer_count += 1 to modify the class variable directly,
giving each timer a unique sequential name for debugging.
@bysiber bysiber force-pushed the fix/timer-class-counter branch from 55d7a42 to 7bdffcd Compare February 20, 2026 06:56
@willmcgugan
Copy link
Member

Your PR has been closed due to a AI policy violation.

Please read the following before submitting further PRs.

https://github.com/Textualize/textual/blob/main/AI_POLICY.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants