Skip to content

Commit a6dd69c

Browse files
authored
Adopt Python 3.7+ syntax (#882)
* Remove __future__ annotations * fd -e py | xargs pyupgrade --py37-plus
1 parent a0ba32d commit a6dd69c

File tree

8 files changed

+53
-59
lines changed

8 files changed

+53
-59
lines changed

tests/test_auth.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def test_get_password_keyring_overrides_prompt(monkeypatch, config):
1717
class MockKeyring:
1818
@staticmethod
1919
def get_password(system, user):
20-
return "{user}@{system} sekure pa55word".format(**locals())
20+
return f"{user}@{system} sekure pa55word"
2121

2222
monkeypatch.setattr(auth, "keyring", MockKeyring)
2323

@@ -68,7 +68,7 @@ class MockKeyring:
6868
@staticmethod
6969
def get_credential(system, user):
7070
return auth.CredentialInput(
71-
"real_user", "real_user@{system} sekure pa55word".format(**locals())
71+
"real_user", f"real_user@{system} sekure pa55word"
7272
)
7373

7474
@staticmethod

tests/test_package.py

Lines changed: 45 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def test_sign_file(monkeypatch):
3636
)
3737
try:
3838
package.sign("gpg2", None)
39-
except IOError:
39+
except OSError:
4040
pass
4141
args = ("gpg2", "--detach-sign", "-a", filename)
4242
assert replaced_check_call.calls == [pretend.call(args)]
@@ -56,7 +56,7 @@ def test_sign_file_with_identity(monkeypatch):
5656
)
5757
try:
5858
package.sign("gpg", "identity")
59-
except IOError:
59+
except OSError:
6060
pass
6161
args = ("gpg", "--detach-sign", "--local-user", "identity", "-a", filename)
6262
assert replaced_check_call.calls == [pretend.call(args)]
@@ -139,51 +139,49 @@ def test_package_safe_name_is_correct(pkg_name, expected_name):
139139
def test_metadata_dictionary_keys():
140140
"""Merge multiple sources of metadata into a single dictionary."""
141141
package = package_file.PackageFile.from_filename(helpers.SDIST_FIXTURE, None)
142-
assert set(package.metadata_dictionary()) == set(
143-
[
144-
# identify release
145-
"name",
146-
"version",
147-
# file content
148-
"filetype",
149-
"pyversion",
150-
# additional meta-data
151-
"metadata_version",
152-
"summary",
153-
"home_page",
154-
"author",
155-
"author_email",
156-
"maintainer",
157-
"maintainer_email",
158-
"license",
159-
"description",
160-
"keywords",
161-
"platform",
162-
"classifiers",
163-
"download_url",
164-
"supported_platform",
165-
"comment",
166-
"md5_digest",
167-
"sha256_digest",
168-
"blake2_256_digest",
169-
# PEP 314
170-
"provides",
171-
"requires",
172-
"obsoletes",
173-
# Metadata 1.2
174-
"project_urls",
175-
"provides_dist",
176-
"obsoletes_dist",
177-
"requires_dist",
178-
"requires_external",
179-
"requires_python",
180-
# Metadata 2.1
181-
"provides_extras",
182-
"description_content_type",
183-
# Metadata 2.2
184-
"dynamic",
185-
]
186-
)
142+
assert set(package.metadata_dictionary()) == {
143+
# identify release
144+
"name",
145+
"version",
146+
# file content
147+
"filetype",
148+
"pyversion",
149+
# additional meta-data
150+
"metadata_version",
151+
"summary",
152+
"home_page",
153+
"author",
154+
"author_email",
155+
"maintainer",
156+
"maintainer_email",
157+
"license",
158+
"description",
159+
"keywords",
160+
"platform",
161+
"classifiers",
162+
"download_url",
163+
"supported_platform",
164+
"comment",
165+
"md5_digest",
166+
"sha256_digest",
167+
"blake2_256_digest",
168+
# PEP 314
169+
"provides",
170+
"requires",
171+
"obsoletes",
172+
# Metadata 1.2
173+
"project_urls",
174+
"provides_dist",
175+
"obsoletes_dist",
176+
"requires_dist",
177+
"requires_external",
178+
"requires_python",
179+
# Metadata 2.1
180+
"provides_extras",
181+
"description_content_type",
182+
# Metadata 2.2
183+
"dynamic",
184+
}
187185

188186

189187
@pytest.mark.parametrize("gpg_signature", [(None), (pretend.stub())])

tests/test_register.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import unicode_literals
2-
31
import pretend
42
import pytest
53

twine/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def dispatch(argv: List[str]) -> Any:
9797
parser.add_argument(
9898
"--version",
9999
action="version",
100-
version="%(prog)s version {} ({})".format(twine.__version__, dep_versions()),
100+
version=f"%(prog)s version {twine.__version__} ({dep_versions()})",
101101
)
102102
parser.add_argument(
103103
"--no-color",

twine/repository.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ def package_is_uploaded(
214214
releases = self._releases_json_data.get(safe_name)
215215

216216
if releases is None:
217-
url = "{url}pypi/{package}/json".format(package=safe_name, url=LEGACY_PYPI)
217+
url = f"{LEGACY_PYPI}pypi/{safe_name}/json"
218218
headers = {"Accept": "application/json"}
219219
response = self.session.get(url, headers=headers)
220220
if response.status_code == 200:
@@ -240,7 +240,7 @@ def release_urls(self, packages: List[package_file.PackageFile]) -> Set[str]:
240240
return set()
241241

242242
return {
243-
"{}project/{}/{}/".format(url, package.safe_name, package.metadata.version)
243+
f"{url}project/{package.safe_name}/{package.metadata.version}/"
244244
for package in packages
245245
}
246246

twine/settings.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
# distributed under the License is distributed on an "AS IS" BASIS,
1212
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
# See the License for the specific language governing permissions and
14-
from __future__ import annotations
15-
1614
# limitations under the License.
1715
import argparse
1816
import contextlib
@@ -138,7 +136,7 @@ def password(self) -> Optional[str]:
138136
# Workaround for https://github.com/python/mypy/issues/5858
139137
return cast(Optional[str], self.auth.password)
140138

141-
def _allow_noninteractive(self) -> contextlib.AbstractContextManager[None]:
139+
def _allow_noninteractive(self) -> "contextlib.AbstractContextManager[None]":
142140
"""Bypass NonInteractive error when client cert is present."""
143141
suppressed = (exceptions.NonInteractive,) if self.client_cert else ()
144142
return contextlib.suppress(*suppressed)

twine/wheel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def py_version(self) -> str:
5353
def find_candidate_metadata_files(names: List[str]) -> List[List[str]]:
5454
"""Filter files that may be METADATA files."""
5555
tuples = [x.split("/") for x in names if "METADATA" in x]
56-
return [x[1] for x in sorted([(len(x), x) for x in tuples])]
56+
return [x[1] for x in sorted((len(x), x) for x in tuples)]
5757

5858
def read(self) -> bytes:
5959
fqn = os.path.abspath(os.path.normpath(self.filename))

twine/wininst.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def read_file(name: str) -> bytes:
4747
for x in names
4848
if x.endswith(".egg-info") or x.endswith("PKG-INFO")
4949
]
50-
schwarz = sorted([(len(x), x) for x in tuples])
50+
schwarz = sorted((len(x), x) for x in tuples)
5151
for path in [x[1] for x in schwarz]:
5252
candidate = "/".join(path)
5353
data = read_file(candidate)

0 commit comments

Comments
 (0)