2
2
import getpass
3
3
import functools
4
4
import typing
5
+ from typing import Optional , Callable
5
6
6
7
import keyring
7
8
@@ -29,7 +30,7 @@ def choose(cls, interactive):
29
30
30
31
@property # type: ignore # https://github.com/python/mypy/issues/1362
31
32
@functools .lru_cache ()
32
- def username (self ):
33
+ def username (self ) -> Optional [ str ] :
33
34
return utils .get_userpass_value (
34
35
self .input .username ,
35
36
self .config ,
@@ -39,7 +40,7 @@ def username(self):
39
40
40
41
@property # type: ignore # https://github.com/python/mypy/issues/1362
41
42
@functools .lru_cache ()
42
- def password (self ):
43
+ def password (self ) -> Optional [ str ] :
43
44
return utils .get_userpass_value (
44
45
self .input .password ,
45
46
self .config ,
@@ -48,7 +49,7 @@ def password(self):
48
49
)
49
50
50
51
@property
51
- def system (self ):
52
+ def system (self ) -> Optional [ str ] :
52
53
return self .config ['repository' ]
53
54
54
55
def get_username_from_keyring (self ):
@@ -62,28 +63,30 @@ def get_username_from_keyring(self):
62
63
except Exception as exc :
63
64
warnings .warn (str (exc ))
64
65
65
- def get_password_from_keyring (self ):
66
+ def get_password_from_keyring (self ) -> Optional [ str ] :
66
67
try :
67
68
return keyring .get_password (self .system , self .username )
68
69
except Exception as exc :
69
70
warnings .warn (str (exc ))
71
+ return None # TODO: mypy shouldn't require this
72
+ return None # any more than it should require this
70
73
71
- def username_from_keyring_or_prompt (self ):
74
+ def username_from_keyring_or_prompt (self ) -> str :
72
75
return (
73
76
self .get_username_from_keyring ()
74
77
or self .prompt ('username' , input )
75
78
)
76
79
77
- def password_from_keyring_or_prompt (self ):
80
+ def password_from_keyring_or_prompt (self ) -> str :
78
81
return (
79
82
self .get_password_from_keyring ()
80
83
or self .prompt ('password' , getpass .getpass )
81
84
)
82
85
83
- def prompt (self , what , how = None ) :
86
+ def prompt (self , what : str , how : Callable ) -> str :
84
87
return how (f"Enter your { what } : " )
85
88
86
89
87
90
class Private (Resolver ):
88
- def prompt (self , what , how = None ):
91
+ def prompt (self , what : str , how : Optional [ Callable ] = None ) -> str :
89
92
raise exceptions .NonInteractive (f"Credential not found for { what } ." )
0 commit comments