Philipp Hörist pushed to branch master at gajim / gajim


Commits:
4a442bdb by lovetox at 2021-12-27T23:17:37+01:00
FileTransfer: Fix type errors

- Add a INIT state, so we don’t have to check for None
- Add type annotations

- - - - -
3001b79a by lovetox at 2021-12-27T23:18:22+01:00
Update pyrightjson.py

- - - - -


5 changed files:

- gajim/common/const.py
- gajim/common/filetransfer.py
- gajim/common/modules/httpupload.py
- gajim/gtk/conversation/rows/file_transfer.py
- pyrightconfig.json


Changes:

=====================================
gajim/common/const.py
=====================================
@@ -781,6 +781,7 @@ def __str__(self):
 
 
 class FTState(Enum):
+    INIT = 'init'
     PREPARING = 'prepare'
     ENCRYPTING = 'encrypting'
     DECRYPTING = 'decrypting'


=====================================
gajim/common/filetransfer.py
=====================================
@@ -12,15 +12,15 @@
 # You should have received a copy of the GNU General Public License
 # along with Gajim. If not, see <http://www.gnu.org/licenses/>.
 
-from typing import Dict
 from typing import Optional
 
 from gajim.common.helpers import Observable
 from gajim.common.const import FTState
 
+
 class FileTransfer(Observable):
 
-    _state_descriptions: Dict[FTState, str] = {}
+    _state_descriptions: dict[FTState, str] = {}
 
     def __init__(self, account: str) -> None:
         Observable.__init__(self)
@@ -30,7 +30,7 @@ def __init__(self, account: str) -> None:
         self._seen: int = 0
         self.size: int = 0
 
-        self._state: Optional[FTState] = None
+        self._state = FTState.INIT
         self._error_text: str = ''
         self._error_domain: Optional[str] = None
 
@@ -39,7 +39,7 @@ def account(self) -> str:
         return self._account
 
     @property
-    def state(self) -> Optional[FTState]:
+    def state(self) -> FTState:
         return self._state
 
     @property
@@ -53,7 +53,7 @@ def is_complete(self) -> bool:
         return self._seen >= self.size
 
     @property
-    def filename(self):
+    def filename(self) -> str:
         raise NotImplementedError
 
     @property
@@ -65,6 +65,8 @@ def error_domain(self) -> Optional[str]:
         return self._error_domain
 
     def get_state_description(self) -> str:
+        if self._state is None:
+            return ''
         return self._state_descriptions.get(self._state, '')
 
     def set_preparing(self) -> None:


=====================================
gajim/common/modules/httpupload.py
=====================================
@@ -351,7 +351,7 @@ def set_uri_transform_func(self, func):
         self._uri_transform_func = func
 
     @property
-    def filename(self):
+    def filename(self) -> str:
         return os.path.basename(self._path)
 
     def set_error(self, domain, text=''):


=====================================
gajim/gtk/conversation/rows/file_transfer.py
=====================================
@@ -83,7 +83,7 @@ def _on_destroy(self, *args: Any) -> None:
         if self._transfer.state.is_active:
             self._transfer.cancel()
 
-        self._transfer = None
+        del self._transfer
         if self._pulse is not None:
             GLib.source_remove(self._pulse)
 


=====================================
pyrightconfig.json
=====================================
@@ -17,6 +17,7 @@
         "gajim/common/configpaths.py",
         "gajim/common/const.py",
         "gajim/common/exceptions.py",
+        "gajim/common/filetransfer.py",
         "gajim/common/ged.py",
         "gajim/common/i18n.py",
         "gajim/common/idle.py",
@@ -33,6 +34,7 @@
         "gajim/gtk/conversation/quote_widget.py",
         "gajim/gtk/conversation/rows/command_output.py",
         "gajim/gtk/conversation/rows/date.py",
+        "gajim/gtk/conversation/rows/file_transfer.py",
         "gajim/gtk/conversation/rows/info.py",
         "gajim/gtk/conversation/rows/muc_join_left.py",
         "gajim/gtk/conversation/rows/muc_subject.py",



View it on GitLab: 
https://dev.gajim.org/gajim/gajim/-/compare/34724b3b004c7ee6b4075f2fdd19d9e341e1c0c4...3001b79a266669046f759a054baa3678f00c0451

-- 
View it on GitLab: 
https://dev.gajim.org/gajim/gajim/-/compare/34724b3b004c7ee6b4075f2fdd19d9e341e1c0c4...3001b79a266669046f759a054baa3678f00c0451
You're receiving this email because of your account on dev.gajim.org.


_______________________________________________
Commits mailing list
[email protected]
https://lists.gajim.org/cgi-bin/listinfo/commits

Reply via email to