Repository: pypa/pip

Issue:
Completion in ZSH doesn't understand that arguments follow certain options
* Pip version: 9.0.1
* Python version: 2.7.12
* Operating system: Ubuntu 16.04

### Description:

Completion in Zsh uses the older `compctl` builtin and returns completions for long options that take arguments with a trailing equals sign. But compctl/Zsh doesn't understand that as meaning that the option takes an argument and adds a space after the equals sign and also tries to complete the next argument if you remove the equals sign as yet another option.

No idea if this is fixable using the older compctl, might want to migrate to the newer compsys... With compsys you will probably have to modify the completion output from Pip or preprocess it in shell code so that it fits what something like `_arguments` expects.

https://github.com/pypa/pip/pull/4842 will make it complete file names by re-implementing that inside pip instead of letting the shell handle it which means certain stuff like colored file names won't work or `zstyle` related settings for file name completion. And it still won't fix the fact that Zsh will add a space after the equals sign...

### What I've run:

```sh
➜ pip install --requirem<tab>
➜ pip install --requirement= # With a space
➜ pip install --requirement=<tab> # Nothing
➜ pip install --requirement= <tab>
➜ pip install --requirement= -- # Sigh...
```



Discussion:
Maybe there's some possibility to collaborate with #5364.

Resolving patch:
diff --git a/src/pip/_internal/commands/completion.py b/src/pip/_internal/commands/completion.py
--- a/src/pip/_internal/commands/completion.py
+++ b/src/pip/_internal/commands/completion.py
@@ -22,15 +22,10 @@
         complete -o default -F _pip_completion {prog}
     """,
     "zsh": """
-        function _pip_completion {{
-          local words cword
-          read -Ac words
-          read -cn cword
-          reply=( $( COMP_WORDS="$words[*]" \\
-                     COMP_CWORD=$(( cword-1 )) \\
-                     PIP_AUTO_COMPLETE=1 $words[1] 2>/dev/null ))
-        }}
-        compctl -K _pip_completion {prog}
+        #compdef -P pip[0-9.]#
+        compadd $( COMP_WORDS="$words[*]" \\
+                   COMP_CWORD=$((CURRENT-1)) \\
+                   PIP_AUTO_COMPLETE=1 $words[1] 2>/dev/null )
     """,
     "fish": """
         function __fish_complete_pip


Test patch:
diff --git a/tests/functional/test_completion.py b/tests/functional/test_completion.py
--- a/tests/functional/test_completion.py
+++ b/tests/functional/test_completion.py
@@ -44,15 +44,10 @@
     (
         "zsh",
         """\
-function _pip_completion {
-  local words cword
-  read -Ac words
-  read -cn cword
-  reply=( $( COMP_WORDS="$words[*]" \\
-             COMP_CWORD=$(( cword-1 )) \\
-             PIP_AUTO_COMPLETE=1 $words[1] 2>/dev/null ))
-}
-compctl -K _pip_completion pip""",
+#compdef -P pip[0-9.]#
+compadd $( COMP_WORDS="$words[*]" \\
+           COMP_CWORD=$((CURRENT-1)) \\
+           PIP_AUTO_COMPLETE=1 $words[1] 2>/dev/null )""",
     ),
     (
         "powershell",
@@ -392,7 +387,8 @@ def test_completion_path_after_option(
     )
 
 
-@pytest.mark.parametrize("flag", ["--bash", "--zsh", "--fish", "--powershell"])
+# zsh completion script doesn't contain pip3
+@pytest.mark.parametrize("flag", ["--bash", "--fish", "--powershell"])
 def test_completion_uses_same_executable_name(
     autocomplete_script: PipTestEnvironment, flag: str, deprecated_python: bool
 ) -> None: