diff --git a/twine/package.py b/twine/package.py
index 230e5ac..e80116a 100644
--- a/twine/package.py
+++ b/twine/package.py
@@ -143,9 +143,10 @@ class PackageFile(object):
 
     def sign(self, sign_with, identity):
         print("Signing {0}".format(self.basefilename))
-        gpg_args = (sign_with, "--detach-sign", "-a", self.filename)
+        gpg_args = (sign_with, "--detach-sign")
         if identity:
             gpg_args += ("--local-user", identity)
+        gpg_args += ("-a", self.filename)
         subprocess.check_call(gpg_args)
 
         with open(self.signed_filename, "rb") as gpg:

Signing fails in version 1.6.0
Signing has stopped to function in the latest version, with the following message:

```
You need a passphrase to unlock the secret key for
user: "foo bar <foo@bar.com>"
1024-bit DSA key, ID ABCDEFGH, created 2015-01-01

gpg: can't open `--local-user': No such file or directory
gpg: signing failed: file open error
```

1.5.0 is ok.
diff --git a/tests/test_package.py b/tests/test_package.py
index 7b15ba9..fcc827a 100644
--- a/tests/test_package.py
+++ b/tests/test_package.py
@@ -53,5 +53,5 @@ def test_sign_file_with_identity(monkeypatch):
         pkg.sign('gpg', 'identity')
     except IOError:
         pass
-    args = ('gpg', '--detach-sign', '-a', filename, '--local-user', 'identity')
+    args = ('gpg', '--detach-sign', '--local-user', 'identity', '-a', filename)
     assert replaced_check_call.calls == [pretend.call(args)]

pip install -e .
parse_log_pytest
pytest
pytest coverage pretend flake8
apt-get update apt-get install -y gcc
3.9
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
certifi==2025.1.31
charset-normalizer==3.4.1
coverage==7.8.0
exceptiongroup @ file:///croot/exceptiongroup_1706031385326/work
flake8==7.2.0
idna==3.10
iniconfig @ file:///home/linux1/recipes/ci/iniconfig_1610983019677/work
mccabe==0.7.0
packaging @ file:///croot/packaging_1734472117206/work
pkginfo==1.12.1.2
pluggy @ file:///croot/pluggy_1733169602837/work
pretend==1.0.9
pycodestyle==2.13.0
pyflakes==3.3.1
pytest @ file:///croot/pytest_1738938843180/work
requests==2.32.3
requests-toolbelt==1.0.0
tomli @ file:///opt/conda/conda-bld/tomli_1657175507142/work
-e git+https://github.com/pypa/twine.git@a0c87357d9d5d588082c9a59f6efc6f6bc3d3498#egg=twine
urllib3==2.3.0

name: twine
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - exceptiongroup=1.2.0=py39h06a4308_0
  - iniconfig=1.1.1=pyhd3eb1b0_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.4.4=h6a678d5_1
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=3.0.16=h5eee18b_0
  - packaging=24.2=py39h06a4308_0
  - pip=25.0=py39h06a4308_0
  - pluggy=1.5.0=py39h06a4308_0
  - pytest=8.3.4=py39h06a4308_0
  - python=3.9.21=he870216_1
  - readline=8.2=h5eee18b_0
  - setuptools=75.8.0=py39h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - tomli=2.0.1=py39h06a4308_0
  - tzdata=2025a=h04d1e81_0
  - wheel=0.45.1=py39h06a4308_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - certifi==2025.1.31
      - charset-normalizer==3.4.1
      - coverage==7.8.0
      - flake8==7.2.0
      - idna==3.10
      - mccabe==0.7.0
      - pkginfo==1.12.1.2
      - pretend==1.0.9
      - pycodestyle==2.13.0
      - pyflakes==3.3.1
      - requests==2.32.3
      - requests-toolbelt==1.0.0
      - urllib3==2.3.0
prefix: /opt/conda/envs/twine

tests/test_package.py::test_sign_file_with_identity
tests/test_package.py::test_sign_file
twine/package.py
twine/package.py