Skip to content

Commit

Permalink
Tidying (#9167)
Browse files Browse the repository at this point in the history
- mypy: keyring, importlib-metadata
- tiny simplifications
  • Loading branch information
dimbleby authored Mar 16, 2024
1 parent 0b6b030 commit c6fbb65
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 25 deletions.
10 changes: 5 additions & 5 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ dulwich = "^0.21.2"
fastjsonschema = "^2.18.0"
importlib-metadata = { version = ">=4.4", python = "<3.10" }
installer = "^0.7.0"
keyring = "^24.0.0"
keyring = "^24.3.1"
# packaging uses calver, so version is unclamped
packaging = ">=23.1"
pexpect = "^4.7.0"
Expand All @@ -64,6 +64,7 @@ pre-commit = ">=2.10"
coverage = ">=7.2.0"
deepdiff = "^6.3"
httpretty = "^1.1"
jaraco-classes = "^3.3.1"
pytest = "^8.0"
pytest-cov = "^4.0"
pytest-mock = "^3.9"
Expand Down Expand Up @@ -161,10 +162,8 @@ exclude = [
module = [
'poetry.plugins.plugin_manager',
'poetry.repositories.installed_repository',
'poetry.utils.env.site_packages',
'tests.console.commands.self.test_show_plugins',
'tests.helpers',
'tests.repositories.test_installed_repository',
]
warn_unused_ignores = false

Expand All @@ -173,7 +172,6 @@ module = [
'deepdiff.*',
'fastjsonschema.*',
'httpretty.*',
'keyring.*',
'pexpect.*',
'requests_toolbelt.*',
'shellingham.*',
Expand Down
4 changes: 1 addition & 3 deletions src/poetry/utils/authenticator.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import annotations

import contextlib
import dataclasses
import functools
import logging
Expand Down Expand Up @@ -167,8 +166,7 @@ def get_session(self, url: str | None = None) -> requests.Session:
def close(self) -> None:
for session in self._sessions_for_netloc.values():
if session is not None:
with contextlib.suppress(AttributeError):
session.close()
session.close()

def __del__(self) -> None:
self.close()
Expand Down
2 changes: 1 addition & 1 deletion src/poetry/utils/env/env_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def activate(self, python: str) -> Env:
venv = venv_path / name

# Create if needed
if not venv.exists() or venv.exists() and create:
if not venv.exists() or create:
in_venv = os.environ.get("VIRTUAL_ENV") is not None
if in_venv or not venv.exists():
create = True
Expand Down
8 changes: 4 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
import keyring
import pytest

from jaraco.classes import properties
from keyring.backend import KeyringBackend
from keyring.backend import properties # type: ignore[attr-defined]
from keyring.backends.fail import Keyring as FailKeyring
from keyring.errors import KeyringError
from keyring.errors import KeyringLocked
Expand Down Expand Up @@ -110,7 +110,7 @@ def __init__(self) -> None:
self._passwords: dict[str, dict[str | None, str | None]] = {}

@properties.classproperty
def priority(self) -> int | float:
def priority(self) -> float:
return 42

def set_password(self, service: str, username: str | None, password: Any) -> None:
Expand All @@ -129,7 +129,7 @@ def delete_password(self, service: str, username: str | None) -> None:

class LockedBackend(KeyringBackend):
@properties.classproperty
def priority(self) -> int | float:
def priority(self) -> float:
return 42

def set_password(self, service: str, username: str | None, password: Any) -> None:
Expand All @@ -147,7 +147,7 @@ def delete_password(self, service: str, username: str | None) -> None:

class ErroneousBackend(FailKeyring):
@properties.classproperty
def priority(self) -> int | float: # type: ignore[override]
def priority(self) -> float:
return 42

def get_credential(self, service: str, username: str | None) -> Any:
Expand Down
16 changes: 8 additions & 8 deletions tests/utils/test_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,17 +337,17 @@ def replace_file(_: str, dest: Path) -> None:

download_mock = mocker.Mock(side_effect=replace_file)

def get_archive(link: Link) -> Path:
path: Path = cache.get_cached_archive_for_link(
link, strict=True, download_func=download_mock
)
return path

with concurrent.futures.ThreadPoolExecutor() as executor:
tasks = []
for _ in range(4):
tasks.append(
executor.submit(
cache.get_cached_archive_for_link,
link,
strict=True,
download_func=download_mock,
)
)
tasks.append(executor.submit(get_archive, link))

concurrent.futures.wait(tasks)
results = set()
for task in tasks:
Expand Down

0 comments on commit c6fbb65

Please sign in to comment.