diff --git a/b2/_internal/_cli/autocomplete_cache.py b/b2/_internal/_cli/autocomplete_cache.py index bf18c475f..a398eefe9 100644 --- a/b2/_internal/_cli/autocomplete_cache.py +++ b/b2/_internal/_cli/autocomplete_cache.py @@ -122,6 +122,11 @@ def autocomplete_from_cache( return def _clean_parser(self, parser: argparse.ArgumentParser) -> None: + # Python 3.14 caches a validation formatter on parsers. The cached formatter can + # contain non-picklable color helpers (local lambdas), so drop it before pickling. + if hasattr(parser, '_cached_formatter'): + parser._cached_formatter = None + parser.register('type', None, identity) def _get_deprecated_actions(actions): diff --git a/changelog.d/+autocomplete-cache-py314.fixed.md b/changelog.d/+autocomplete-cache-py314.fixed.md new file mode 100644 index 000000000..599e8b6a5 --- /dev/null +++ b/changelog.d/+autocomplete-cache-py314.fixed.md @@ -0,0 +1 @@ +Fixed autocomplete parser cache on Python 3.14.2+ by clearing argparse's cached validation formatter before pickling the parser. This avoids failures caused by non-picklable color formatting lambdas stored in the cached formatter.