Package: python3.12
Version: 3.12.7-3
Severity: normal
X-Debbugs-Cc: trevor.l.da...@gmail.com

Dear Maintainer,

I'm observing a bug in
`argparse.ArgumentParser().parse_known_intermixed_args()` in Debian Testing's
version of Python 3.12.7.  However if I instead install Python 3.12.7 by
compiling from the official Python source the bug goes away so it seems this
bug is may be specific to Debian Testing's version of Python 3.12.7.

To reproduce the bug:

1. Start Debian Testing in Docker with `docker run --rm -ti debian:testing`
2. Within docker container install `python3.12` with `apt-get update && apt-get
install -y python3.12`
3. Start the python shell using the command `python3.12` and run the following
python code:

```python
from argparse import ArgumentParser
parser = ArgumentParser()
parser.add_argument("--foo")
parser.add_argument("cmd")
parser.add_argument("rest", nargs="*", type=int)
args = ["doit", "1", "--foo", "bar", "2", "3", "-n", "4"]
a_r = parser.parse_known_intermixed_args(args)
print(a_r)
```

I observe the following incorrect output:

```python
(Namespace(foo='bar', cmd='doit', rest=[1, 2, 3, 4]), ['-n'])
```

However the expected output is instead:

```python
(Namespace(foo='bar', cmd='doit', rest=[1, 2, 3]), ['-n', '4'])
```

Notice the different location for the `4`.

To install Python 3.12 from the official source in the Debian Testing container
I use the following bash commands:

```bash
apt-get update && apt-get install -y gcc make wget xz-utils
wget https://www.python.org/ftp/python/3.12.7/Python-3.12.7.tar.xz
tar xf Python-3.12.7.tar.xz
cd Python-3.12.7
./configure
make
```

Then after I start this compiled-from-official-source version of Python 3.12
with `./python` and run the previous python commands I get the expected output:

```python
(Namespace(foo='bar', cmd='doit', rest=[1, 2, 3]), ['-n', '4'])
```

Thanks,

Trevor


-- System Information:
Debian Release: bookworm/sid
  APT prefers jammy-updates
  APT policy: (500, 'jammy-updates'), (500, 'jammy-security'), (500, 'jammy'), 
(100, 'jammy-backports')
Architecture: amd64 (x86_64)
Foreign Architectures: i386

Kernel: Linux 6.9.3-76060903-generic (SMP w/20 CPU threads; PREEMPT)
Kernel taint flags: TAINT_OOT_MODULE, TAINT_UNSIGNED_MODULE
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8), LANGUAGE not set
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled

Reply via email to