Skip to content

Commit

Permalink
Honor types in dependencies (#735)
Browse files Browse the repository at this point in the history
* Install the project and dependencies in 'types'. Ref #733.

* Cast parameters to match keyring's expectations.

* Bump requirement on keyring in typechecks

* Remove ignores for importlib_metadata and keyring, both typed.
  • Loading branch information
jaraco committed Feb 27, 2021
1 parent 22aaa04 commit d01fdfa
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
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

0 comments on commit d01fdfa

Please sign in to comment.