Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Honor types in dependencies #735

Merged
merged 4 commits into from Feb 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 0 additions & 8 deletions mypy.ini
Expand Up @@ -22,14 +22,6 @@ strict_equality = True
; https://github.com/tartley/colorama/issues/206
ignore_missing_imports = True

[mypy-importlib_metadata]
; https://github.com/python/importlib_metadata/issues/10
ignore_missing_imports = True

[mypy-keyring]
; https://github.com/jaraco/keyring/issues/437
ignore_missing_imports = True

[mypy-pkginfo]
; https://bugs.launchpad.net/pkginfo/+bug/1876591
ignore_missing_imports = True
Expand Down
3 changes: 2 additions & 1 deletion tox.ini
Expand Up @@ -69,10 +69,11 @@ commands =
flake8 twine/ tests/

[testenv:types]
skip_install = True
deps =
mypy
lxml
# required for more thorough type declarations
keyring >= 22.3
commands =
mypy --html-report mypy --txt-report mypy {posargs:twine}
python -c 'with open("mypy/index.txt") as f: print(f.read())'
Expand Down
7 changes: 5 additions & 2 deletions twine/auth.py
Expand Up @@ -55,7 +55,8 @@ def system(self) -> Optional[str]:

def get_username_from_keyring(self) -> Optional[str]:
try:
creds = keyring.get_credential(self.system, None)
system = cast(str, self.system)
creds = keyring.get_credential(system, None)
if creds:
return cast(str, creds.username)
except AttributeError:
Expand All @@ -67,7 +68,9 @@ def get_username_from_keyring(self) -> Optional[str]:

def get_password_from_keyring(self) -> Optional[str]:
try:
return cast(str, keyring.get_password(self.system, self.username))
system = cast(str, self.system)
username = cast(str, self.username)
return cast(str, keyring.get_password(system, username))
except Exception as exc:
warnings.warn(str(exc))
return None
Expand Down