Skip to content

Compatibility with click 8.2+ - #132

Merged
auvipy merged 6 commits into
click-contrib:masterfrom
stratakis:click_compat
Mar 26, 2026
Merged

Compatibility with click 8.2+#132
auvipy merged 6 commits into
click-contrib:masterfrom
stratakis:click_compat

Conversation

@stratakis

Copy link
Copy Markdown
Contributor

Fixes #128

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates click-repl to work with Click 8.2+ where Context.protected_args is no longer assignable, preventing REPL sessions from crashing with AttributeError.

Changes:

  • Add compatibility helpers to read/write protected args across Click versions and use them in REPL dispatch + context resolution.
  • Relax Click dependency constraint to allow Click 8.2+ (<9.0).
  • Adjust completion-related tests to use explicit command names for stability.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
click_repl/utils.py Adds _get_protected_args / _set_protected_args and uses them in _resolve_context.
click_repl/_repl.py Uses the new protected-args helpers to avoid assigning to a read-only property on Click 8.2+.
setup.cfg Updates Click requirement from <8.2.0 to <9.0.
tests/test_basic.py Uses explicit command names in completion tests.
tests/test_command_collection.py Uses explicit command names for command collection completion.
tests/test_completion/test_common_tests/test_hidden_cmd_and_args.py Uses explicit names for hidden commands and nested group name.
tests/test_completion/test_click_version_le_7/test_arg_completion_v7.py Uses explicit name for tuple-type autocompletion command.
tests/test_completion/test_click_version_ge_8/test_option_completion_v8.py Uses explicit command name in option shell-complete test.
tests/test_completion/test_click_version_ge_8/test_arg_completion_v8.py Uses explicit command names and updates the invoked completion strings accordingly.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread click_repl/utils.py Outdated
Comment thread click_repl/utils.py Outdated

@auvipy auvipy left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please also check the failing tests in the CI

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread setup.cfg
Click 8.2 auto-strips _cmd/_command/_group/_grp suffixes from
function-derived command names. Pin names with explicit name= parameters
so tests work across click versions.
@stratakis

Copy link
Copy Markdown
Contributor Author

Made some more changes for the CI, as well as for future deprecations. I can either split those into different PRs or squash some commits. The main change on top is to provide a proper CI coverage for newest python's and click versions.

@auvipy

auvipy commented Feb 19, 2026

Copy link
Copy Markdown
Collaborator

=================================== FAILURES ===================================
_________________________ test_click7_autocomplete_arg _________________________

  @pytest.mark.skipif(
      hasattr(click, "shell_complete"),
      reason="click-v7 old autocomplete function is not available, so skipped",
  )
  def test_click7_autocomplete_arg():
      def shell_complete_func(ctx, args, incomplete):
          return [name for name in ("foo", "bar") if name.startswith(incomplete)]
  
      @root_command.command()
      @click.argument("handler", autocompletion=shell_complete_func)
  def autocompletion_arg_cmd2(handler):

tests/test_completion/test_click_version_le_7/test_arg_completion_v7.py:25:

Click 8.2 made Context.protected_args a read-only property, renaming
the underlying storage to _protected_args. Add compat helpers that
use the private attribute when available, falling back to the public
one for older click versions.
Drop Python 3.6/3.7/3.8, add 3.12/3.13/3.14 to match the
test matrix.
@stratakis

Copy link
Copy Markdown
Contributor Author

Rebased, should hopefully be resolved.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated 5 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tox.ini
Comment thread tox.ini Outdated
Comment thread tox.ini
Comment thread setup.cfg
Comment thread .github/workflows/tests.yml

@auvipy auvipy left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please cross check the auto suggestions. some might be valid

Removed the click-version matrix dimension in GH Actions as it had
no effect on tox's isolated virtualenvs.

Add dedicated tox envs that pin click 8.1.8, 8.2.1 and 8.3.1, run on all
compatible Python versions.

Use basepython = python3 for mypy and flake8 so they work on any
local Python. The gh-actions mapping controls the CI version.
click.__version__ is deprecated and will be removed in click 9.1.
Use importlib.metadata.version() to determine the major version for
the skippable tests.
@auvipy
auvipy merged commit b84191a into click-contrib:master Mar 26, 2026
14 checks passed
@stratakis
stratakis deleted the click_compat branch March 26, 2026 14:43
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.

Support Click 8.2.0 (fix AttributeError: property 'protected_args' of 'Context' object has no setter)

3 participants