Add typing for all version upgrade plug-ins

Hopefully we'll take this typing along when we next copy-paste the stuffs.

Contributes to issue CURA-5936.
This commit is contained in:
Ghostkeeper 2018-11-14 13:41:23 +01:00
parent fe66d15b9e
commit ae2b312472
No known key found for this signature in database
GPG key ID: 86BEF881AE2CF276
21 changed files with 200 additions and 150 deletions

View file

@ -1,10 +1,9 @@
# Copyright (c) 2016 Ultimaker B.V.
# Copyright (c) 2018 Ultimaker B.V.
# Cura is released under the terms of the LGPLv3 or higher.
import configparser #To read config files.
import io #To write config files to strings as if they were files.
from typing import Dict
from typing import List
from typing import Dict, List, Optional, Tuple
import UM.VersionUpgrade
from UM.Logger import Logger
@ -15,7 +14,7 @@ from UM.Logger import Logger
# \param serialised The serialised form of a profile in version 1.
# \param filename The supposed filename of the profile, without extension.
# \return A profile instance, or None if the file format is incorrect.
def importFrom(serialised, filename):
def importFrom(serialised: str, filename: str) -> Optional["Profile"]:
try:
return Profile(serialised, filename)
except (configparser.Error, UM.VersionUpgrade.FormatException, UM.VersionUpgrade.InvalidVersionException):
@ -77,11 +76,11 @@ class Profile:
#
# \return A tuple containing the new filename and a serialised form of
# this profile, serialised in version 2 of the file format.
def export(self):
def export(self) -> Optional[Tuple[List[str], List[str]]]:
import VersionUpgrade21to22 # Import here to prevent circular dependencies.
if self._name == "Current settings":
return None, None #Can't upgrade these, because the new current profile needs to specify the definition ID and the old file only had the machine instance, not the definition.
return None #Can't upgrade these, because the new current profile needs to specify the definition ID and the old file only had the machine instance, not the definition.
config = configparser.ConfigParser(interpolation = None)