Skip to content

Commit 563d6c4

Browse files
committed
Add types to auth.Resolver and its methods
1 parent fceecdf commit 563d6c4

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

twine/auth.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import getpass
33
import functools
44
import typing
5+
from typing import Optional, Callable
56

67
import keyring
78

@@ -29,7 +30,7 @@ def choose(cls, interactive):
2930

3031
@property # type: ignore # https://github.com/python/mypy/issues/1362
3132
@functools.lru_cache()
32-
def username(self):
33+
def username(self) -> Optional[str]:
3334
return utils.get_userpass_value(
3435
self.input.username,
3536
self.config,
@@ -39,7 +40,7 @@ def username(self):
3940

4041
@property # type: ignore # https://github.com/python/mypy/issues/1362
4142
@functools.lru_cache()
42-
def password(self):
43+
def password(self) -> Optional[str]:
4344
return utils.get_userpass_value(
4445
self.input.password,
4546
self.config,
@@ -48,7 +49,7 @@ def password(self):
4849
)
4950

5051
@property
51-
def system(self):
52+
def system(self) -> Optional[str]:
5253
return self.config['repository']
5354

5455
def get_username_from_keyring(self):
@@ -62,28 +63,30 @@ def get_username_from_keyring(self):
6263
except Exception as exc:
6364
warnings.warn(str(exc))
6465

65-
def get_password_from_keyring(self):
66+
def get_password_from_keyring(self) -> Optional[str]:
6667
try:
6768
return keyring.get_password(self.system, self.username)
6869
except Exception as exc:
6970
warnings.warn(str(exc))
71+
return None # TODO: mypy shouldn't require this
72+
return None # any more than it should require this
7073

71-
def username_from_keyring_or_prompt(self):
74+
def username_from_keyring_or_prompt(self) -> str:
7275
return (
7376
self.get_username_from_keyring()
7477
or self.prompt('username', input)
7578
)
7679

77-
def password_from_keyring_or_prompt(self):
80+
def password_from_keyring_or_prompt(self) -> str:
7881
return (
7982
self.get_password_from_keyring()
8083
or self.prompt('password', getpass.getpass)
8184
)
8285

83-
def prompt(self, what, how=None):
86+
def prompt(self, what: str, how: Callable) -> str:
8487
return how(f"Enter your {what}: ")
8588

8689

8790
class Private(Resolver):
88-
def prompt(self, what, how=None):
91+
def prompt(self, what: str, how: Optional[Callable] = None) -> str:
8992
raise exceptions.NonInteractive(f"Credential not found for {what}.")

0 commit comments

Comments
 (0)