Browse Source

Added typing fof KeyringAttributes

This should hopefully shut mypy up.

Contributes to CURA-7180
jelle Spijker 3 years ago
parent
commit
33a812d696
1 changed files with 6 additions and 5 deletions
  1. 6 5
      cura/OAuth2/KeyringAttribute.py

+ 6 - 5
cura/OAuth2/KeyringAttribute.py

@@ -1,6 +1,6 @@
 # Copyright (c) 2021 Ultimaker B.V.
 # Cura is released under the terms of the LGPLv3 or higher.
-from typing import Type, TYPE_CHECKING
+from typing import Type, TYPE_CHECKING, Optional, List
 
 import keyring
 from keyring.backend import KeyringBackend
@@ -20,14 +20,15 @@ if Platform.isWindows() and hasattr(sys, "frozen"):
     keyring.set_keyring(WinVaultKeyring())
 
 # Even if errors happen, we don't want this stored locally:
-DONT_EVER_STORE_LOCALLY = ["refresh_token"]
+DONT_EVER_STORE_LOCALLY: List[str] = ["refresh_token"]
+
 
 class KeyringAttribute:
     """
     Descriptor for attributes that need to be stored in the keyring. With Fallback behaviour to the preference cfg file
     """
-    def __get__(self, instance: Type["BaseModel"], owner: type) -> str:
-        if self._store_secure:
+    def __get__(self, instance: BaseModel, owner: type) -> Optional[str]:
+        if self._store_secure:  # type: ignore
             try:
                 value = keyring.get_password("cura", self._keyring_name)
                 return value if value != "" else None
@@ -38,7 +39,7 @@ class KeyringAttribute:
         else:
             return getattr(instance, self._name)
 
-    def __set__(self, instance: Type["BaseModel"], value: str):
+    def __set__(self, instance: BaseModel, value: Optional[str]):
         if self._store_secure:
             setattr(instance, self._name, None)
             try: