FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Python 3.15: `AttributeError` from `argparse` on every `tmuxp` command · Issue #1094 · tmux-python/tmuxp · GitHub

Repository navigation

Python 3.15: AttributeError from argparse on every tmuxp command #1094

Closed

Description

Step 1: Provide a summary of your problem

On Python 3.15.0, every tmuxp invocation, including tmuxp --version, fails with AttributeError: 'NoneType' object has no attribute 'reset' while the argument parser is being built. TmuxpHelpFormatter declares a class attribute _theme that shadows the _theme property of argparse.HelpFormatter, which 3.15 added to support coloured help. Much of the test suite fails for the same reason; it passes on Python 3.14.

Step 2: Provide tmuxp details

tmuxp debug-info crashes on 3.15 with the same error, so these versions come from the checkout and uv.lock:

Environment
  • tmuxp 1.74.0 at ddd6cce, libtmux 0.61.0 (from uv.lock)
  • Python 3.15.0
  • uv 0.13.1
  • Linux x86_64

Step 3: Describe the problem:

Steps to reproduce:

  1. Check out the repository and install the project with all extras and dev dependencies on Python 3.15.
$ uv sync --python 3.15 --all-extras --dev
  1. Run any command.
$ uv run tmuxp --version
  1. Or run a single test.
$ uv run py.test tests/cli/test_cli.py -k help_long_flag

Observed Results:

AttributeError: 'NoneType' object has no attribute 'reset'

Without colour (no TTY, or NO_COLOR set), create_themed_formatter() binds theme = None, so argparse reads None for self._theme in _apply_text_markup. With colour forced (FORCE_COLOR=1), the bound HelpTheme is read instead and fails with AttributeError: 'HelpTheme' object has no attribute 'prog_extra', because argparse expects its own theme object.

Traceback from uv run tmuxp --version
Traceback (most recent call last):
  File "<repo>/.venv/bin/tmuxp", line 10, in <module>
    sys.exit(cli.cli())
             ~~~~~~~^^
  File "<repo>/src/tmuxp/cli/__init__.py", line 297, in cli
    parser = create_parser()
  File "<repo>/src/tmuxp/cli/__init__.py", line 169, in create_parser
    parser = argparse.ArgumentParser(
        prog="tmuxp",
        description=CLI_DESCRIPTION,
        formatter_class=formatter_class,
    )
  File "<stdlib>/argparse.py", line 2058, in __init__
    self.add_argument(
  File "<stdlib>/argparse.py", line 1695, in add_argument
    self._check_help(action)
  File "<stdlib>/argparse.py", line 1887, in _check_help
    formatter._expand_help(action)
  File "<stdlib>/argparse.py", line 716, in _expand_help
    return self._apply_text_markup(help_string)
  File "<stdlib>/argparse.py", line 568, in _apply_text_markup
    if not t.reset:
           ^^^^^^^
AttributeError: 'NoneType' object has no attribute 'reset'

Expected Results:

tmuxp --version prints the version, and the test suite passes as it does on Python 3.14.

Relevant Code:

Python 3.15 added backtick markup to argparse help text (What's New in Python 3.15, python/cpython#142389, python/cpython#149375). argparse.HelpFormatter now computes its colours through a read-only _theme property and reads it in _apply_text_markup. The excerpt is from Lib/argparse.py at v3.15.0 and lines 559-570:

    @property
    def _theme(self):
        if self._cached_theme is None:
            self._get_theme_and_decolor()
        return self._cached_theme

    def _apply_text_markup(self, text):
        ...
        t = self._theme
        if not t.reset:
            return text

tmuxp's formatter already used _theme for its own HelpTheme, so it now collides with the stdlib name: the class attribute at src/tmuxp/cli/_formatter.py lines 85-86 replaces the property, and the instance assignment in lines 391-396 sets the value argparse then reads. The parser is built at src/tmuxp/cli/__init__.py lines 163-173, and ArgumentParser.__init__ adds -h/--help, whose help text goes through _apply_text_markup immediately.

Proposal

Store tmuxp's theme under a name argparse does not use, for example _help_theme, in TmuxpHelpFormatter._fill_text, _colorize_example_line, and create_themed_formatter, and leave _theme to the standard library.

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL