Inconsistent argument parsing behavior across Python versions (< 3.13 vs 3.13+)
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 48/100
Línea de trabajo
Comienza en httpie/cli/argparser.py, especialmente en parse_args y sus llamadas a parse_known_args alrededor de las líneas 97, 129 y 159. Reproduce los dos comandos con Python 3.11, 3.12 y 3.13; después, compara el comportamiento del parser con el posible enfoque parse_intermixed_args. Se considera terminado cuando el proyecto tenga una solución decidida —un parsing coherente o una limitación documentada explícitamente— validada en todas las versiones de Python compatibles.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Checklist
- I've searched for similar issues.
- I'm using the latest version of HTTPie.
Summary
I discovered that the position of optional flags (like -v) affects argument parsing differently depending on the Python version. This is due to improvements in Python 3.13's argparse module, but it creates an inconsistent user experience for users on Python 3.11/3.12 (which are still officially supported until 2027-2028).
Minimal reproduction code and steps
The position of the -v flag affects argument parsing differently depending on the Python version being used.
Test Case 1: -v flag after URL (fails on Python 3.11-3.12, works on 3.13+)
$ http --offline --ignore-stdin post pie.dev/post -v 'header1:xyz' x=1
Test Case 2: -v flag before URL (fails on all versions tested)
$ http --offline --ignore-stdin post -v pie.dev/post 'header1:xyz' x=1
Current result
Python 3.11 (Version 3.11.15)
$ http --offline --ignore-stdin post pie.dev/post -v 'header1:xyz' x=1
usage:
http [METHOD] URL [REQUEST_ITEM ...]
error:
unrecognized arguments: header1:xyz x=1
for more information:
run 'http --help' or visit https://httpie.io/docs/cli
Python 3.12 (Version 3.12.3)
$ http --offline --ignore-stdin post pie.dev/post -v 'header1:xyz' x=1
usage:
http [METHOD] URL [REQUEST_ITEM ...]
error:
unrecognized arguments: header1:xyz x=1
for more information:
run 'http --help' or visit https://httpie.io/docs/cli
Python 3.13 (Version 3.13.5) or higher
$ http --offline --ignore-stdin post pie.dev/post -v 'header1:xyz' x=1
POST /post HTTP/1.1
Accept-Encoding: gzip, deflate
Connection: keep-alive
Content-Length: 10
User-Agent: HTTPie/3.2.4
Accept: application/json, */*;q=0.5
Content-Type: application/json
header1: xyz
Host: pie.dev
{"x": "1"}
✅ Works correctly on Python 3.13+
Expected result
Ideally, the command should work consistently across all supported Python versions, regardless of whether optional flags like -v are placed before or after the URL.
While I understand this is caused by Python's argparse improvements in 3.13, I wanted to bring this to your attention because:
- Many users are still on Python 3.11/3.12 (officially supported until 2027-2028)
- This creates a confusing user experience where the same command works differently
- There might be room for improvement through documentation or potential workarounds
Debug output
Python 3.12
$ http --debug --offline --ignore-stdin post pie.dev/post -v 'header1:xyz' x=1
HTTPie 3.2.4
Requests 2.33.1
Pygments 2.20.0
Python 3.12.3 (main, Mar 23 2026, 19:04:32) [GCC 13.3.0]
/home/user/env312/bin/python
Linux 5.15.167.4-microsoft-standard-WSL2
<Environment {...}>
<PluginManager {...}>
usage:
http [METHOD] URL [REQUEST_ITEM ...]
error:
unrecognized arguments: header1:xyz x=1
for more information:
run 'http --help' or visit https://httpie.io/docs/cli
Python 3.13
$ http --debug --offline --ignore-stdin post pie.dev/post -v 'header1:xyz' x=1
HTTPie 3.2.4
Requests 2.33.1
Pygments 2.20.0
Python 3.13.5 (main, Apr 27 2026, 03:43:50) [GCC 9.5.0]
/home/user/env313/bin/python
Linux 5.15.167.4-microsoft-standard-WSL2
<Environment {...}>
<PluginManager {...}>
>>> requests.request(**{'auth': None,
'data': b'{"x": "1"}',
'headers': <HTTPHeadersDict(...)>,
'method': 'post',
'params': <generator object MultiValueOrderedDict.items at 0x...>,
'url': 'http://pie.dev/post'})
POST /post HTTP/1.1
Accept-Encoding: gzip, deflate
Connection: keep-alive
Content-Length: 10
User-Agent: HTTPie/3.2.4
Accept: application/json, */*;q=0.5
Content-Type: application/json
header1: xyz
Host: pie.dev
{"x": "1"}
Additional information
This issue appears to be caused by changes in Python's argparse.ArgumentParser.parse_known_args() behavior between Python 3.12 and 3.13.
HTTPie uses parse_known_args() in httpie/cli/argparser.py (lines 97, 129, 159) to handle the mix of positional and optional arguments. The Python 3.13 release includes improvements to argparse that better handle intermixed optional and positional arguments.
Code Reference
The parsing happens in httpie/cli/argparser.py:
def parse_args(
self,
env: Environment,
args=None,
namespace=None
) -> argparse.Namespace:
self.env = env
self.args, no_options = self.parse_known_args(args, namespace) # Line 159
# ... rest of the method
Impact
- Users on Python 3.11 and 3.12 (which are still widely used) experience inconsistent behavior
- The position of optional flags shouldn't matter for argument parsing
- This creates confusion for users who might be used to putting flags anywhere in the command
Possible Approaches (open for discussion)
- Documentation: Add a note about this limitation for Python < 3.13 users (recommend placing optional flags before the URL)
- Workaround consideration: Evaluate if using
argparse.ArgumentParser.parse_intermixed_args()would help (available since Python 3.7) - Informational only: Perhaps this is just something to be aware of as Python 3.11/3.12 approach EOL
I'm happy to contribute documentation updates or help test any potential solutions if you think this is worth addressing. I'm also open to this just being "working as intended" given the Python version constraints.
Related
- Python 3.13 What's New: https://docs.python.org/3/whatsnew/3.13.html#argparse
- Python argparse documentation: https://docs.python.org/3/library/argparse.html
- #1828 (parser complexity / mixed responsibilities)
This issue focuses specifically on observable cross-version parsing behavior.
Environment
- HTTPie version: 3.2.4
- Python versions tested: 3.11.15, 3.12.3, 3.13.5, 3.14.4
- OS: Linux (WSL2)
- Requests version: 2.33.1
- Lenguaje dominante
- Python
- Estrellas
- 38.6k
- Forks
- 4k
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de httpie/cli
-
new
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
-
Dificultad 3/5 1-2 días Aptitud para principiantes 55/100
-
argparser.py: HTTPieArgumentParser has high cyclomatic complexity and mixed responsibilities Abierto
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 25/100
Todos los issues de httpie/cli
Issues similares
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 75/100
-
hcocena Abiertopolicies-accepted pre-review precheck-passed
Dificultad 1/5 Menos de una hora Aptitud para principiantes 88/100
Bioconductor/BiocContributions#214 · 5 comentarios ·
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 92/100
TencentCloud/Octop#1169 · 1 comentario ·
-
[开源推荐] 在老板拷问你之前,先让 AI 灵魂拷问你 Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
521xueweihan/HelloGitHub#3778 ·
-
The version checker's trailing attribute region has no control for a less-than inside a quoted value Abiertoarea: dashboard area: tests bug perceived difficulty: 2 python
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
Nitjsefnie-Harness-Commons/daedalus#1105 · 1 comentario ·