File: min-difflib-argparse.diff

package info (click to toggle)
python3.14 3.14.0-5
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 169,680 kB
  • sloc: python: 751,968; ansic: 717,163; xml: 31,250; sh: 5,989; cpp: 4,063; makefile: 1,995; objc: 787; lisp: 502; javascript: 136; asm: 75; csh: 12
file content (21 lines) | stat: -rw-r--r-- 994 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Description: Debian: Degrade argparse gracefully without difflib
 python3.X-minimal doesn't include difflib, so don't offer suggestions.

Forwarded: not-needed
--- a/Lib/argparse.py
+++ b/Lib/argparse.py
@@ -2681,8 +2681,12 @@ class ArgumentParser(_AttributeHolder, _
 
             if self.suggest_on_error and isinstance(value, str):
                 if all(isinstance(choice, str) for choice in action.choices):
-                    import difflib
-                    suggestions = difflib.get_close_matches(value, action.choices, 1)
+                    try:
+                        import difflib
+                    except ImportError:
+                        suggestions = None
+                    else:
+                        suggestions = difflib.get_close_matches(value, action.choices, 1)
                     if suggestions:
                         args['closest'] = suggestions[0]
                         msg = _('invalid choice: %(value)r, maybe you meant %(closest)r? '