Skip to content
Snippets Groups Projects
Verified Commit 74f96a33 authored by Daniel Hornung's avatar Daniel Hornung
Browse files

WIP: mypy

parent 9ae5cd87
Branches
Tags
2 merge requests!175BUG: Request responses without the "Set-Cookie" header no longer overwrite the...,!164Fix mypy errors
Pipeline #58009 failed
...@@ -101,11 +101,14 @@ class Version(): ...@@ -101,11 +101,14 @@ class Version():
# pylint: disable=redefined-builtin # pylint: disable=redefined-builtin
def __init__(self, id: Optional[str] = None, date: Optional[str] = None, def __init__(self, id: Optional[str] = None, date: Optional[str] = None,
username: Optional[str] = None, realm: Optional[str] = None, username: Optional[str] = None, realm: Optional[str] = None,
predecessors: Optional[List[Version]] = None, successors: Optional[List[Version]] = None, predecessors: Optional[List[Version]] = None,
successors: Optional[List[Version]] = None,
is_head: Union[bool, str, None] = False, is_head: Union[bool, str, None] = False,
is_complete_history: Union[bool, str, None] = False): is_complete_history: Union[bool, str, None] = False):
"""Typically the `predecessors` or `successors` should not "link back" to an existing Version """Typically the `predecessors` or `successors` should not "link back" to an existing
object.""" Version object.
"""
self.id = id self.id = id
self.date = date self.date = date
self.username = username self.username = username
...@@ -205,8 +208,8 @@ class Version(): ...@@ -205,8 +208,8 @@ class Version():
version : Version version : Version
a new version instance a new version instance
""" """
predecessors = [Version.from_xml(p) for p in xml if p.tag.lower() == "predecessor"] predecessors = [Version.from_xml(p) for p in xml if str(p.tag).lower() == "predecessor"]
successors = [Version.from_xml(s) for s in xml if s.tag.lower() == "successor"] successors = [Version.from_xml(s) for s in xml if str(s.tag).lower() == "successor"]
return Version(id=xml.get("id"), date=xml.get("date"), return Version(id=xml.get("id"), date=xml.get("date"),
is_head=xml.get("head"), is_head=xml.get("head"),
is_complete_history=xml.get("completeHistory"), is_complete_history=xml.get("completeHistory"),
......
...@@ -103,9 +103,12 @@ class _WrappedHTTPResponse(CaosDBHTTPResponse): ...@@ -103,9 +103,12 @@ class _WrappedHTTPResponse(CaosDBHTTPResponse):
if len(self._buffer) >= size: if len(self._buffer) >= size:
# still enough bytes in the buffer # still enough bytes in the buffer
# FIXME: `chunk`` is used before definition # FIXME: `chunk`` is used before definition
result = chunk[:size] raise NotImplementedError("chunk is undefined")
self._buffer = chunk[size:]
return result # # old code:
# result = chunk[:size]
# self._buffer = chunk[size:]
# return result
if self._generator is None: if self._generator is None:
# first call to this method # first call to this method
...@@ -218,7 +221,7 @@ class _DefaultCaosDBServerConnection(CaosDBServerConnection): ...@@ -218,7 +221,7 @@ class _DefaultCaosDBServerConnection(CaosDBServerConnection):
"Connection failed. Network or server down? " + str(conn_err) "Connection failed. Network or server down? " + str(conn_err)
) )
def configure(self, **config): def configure(self, **config) -> None:
"""configure. """configure.
Configure the http connection. Configure the http connection.
...@@ -551,9 +554,9 @@ class _Connection(object): # pylint: disable=useless-object-inheritance ...@@ -551,9 +554,9 @@ class _Connection(object): # pylint: disable=useless-object-inheritance
__instance = None __instance = None
def __init__(self): def __init__(self) -> None:
self._delegate_connection: Optional[CaosDBServerConnection] = None self._delegate_connection: Optional[CaosDBServerConnection] = None
self._authenticator: Optional[CredentialsAuthenticator] = None self._authenticator: Optional[AbstractAuthenticator] = None
self.is_configured = False self.is_configured = False
@classmethod @classmethod
...@@ -563,7 +566,7 @@ class _Connection(object): # pylint: disable=useless-object-inheritance ...@@ -563,7 +566,7 @@ class _Connection(object): # pylint: disable=useless-object-inheritance
return cls.__instance return cls.__instance
def configure(self, **config): def configure(self, **config) -> _Connection:
self.is_configured = True self.is_configured = True
if "implementation" not in config: if "implementation" not in config:
...@@ -571,8 +574,7 @@ class _Connection(object): # pylint: disable=useless-object-inheritance ...@@ -571,8 +574,7 @@ class _Connection(object): # pylint: disable=useless-object-inheritance
"Missing CaosDBServerConnection implementation. You did not " "Missing CaosDBServerConnection implementation. You did not "
"specify an `implementation` for the connection.") "specify an `implementation` for the connection.")
try: try:
self._delegate_connection: CaosDBServerConnection = config["implementation"]( self._delegate_connection = config["implementation"]()
)
if not isinstance(self._delegate_connection, if not isinstance(self._delegate_connection,
CaosDBServerConnection): CaosDBServerConnection):
...@@ -762,6 +764,7 @@ class _Connection(object): # pylint: disable=useless-object-inheritance ...@@ -762,6 +764,7 @@ class _Connection(object): # pylint: disable=useless-object-inheritance
if self._authenticator is None: if self._authenticator is None:
raise ValueError( raise ValueError(
"No authenticator set. Please call configure_connection() first.") "No authenticator set. Please call configure_connection() first.")
assert isinstance(self._authenticator, CredentialsAuthenticator)
if self._authenticator._credentials_provider is None: if self._authenticator._credentials_provider is None:
raise ValueError( raise ValueError(
"No credentials provider set. Please call configure_connection() first.") "No credentials provider set. Please call configure_connection() first.")
......
...@@ -36,9 +36,9 @@ logger = logging.getLogger(__name__) ...@@ -36,9 +36,9 @@ logger = logging.getLogger(__name__)
def get_origin_url_in(folder: str): def get_origin_url_in(folder: str):
"""return the Fetch URL of the git repository in the given folder.""" """return the Fetch URL of the git repository in the given folder."""
with tempfile.NamedTemporaryFile(delete=False, mode="w") as t: with tempfile.NamedTemporaryFile(delete=False, mode="w", encoding="utf8") as tempf:
call(["git", "remote", "show", "origin"], stdout=t, cwd=folder) call(["git", "remote", "show", "origin"], stdout=tempf, cwd=folder)
with open(t.name, "r") as t: with open(tempf.name, "r", encoding="utf8") as t:
urlString = "Fetch URL:" urlString = "Fetch URL:"
for line in t.readlines(): for line in t.readlines():
...@@ -63,9 +63,9 @@ def get_branch_in(folder: str): ...@@ -63,9 +63,9 @@ def get_branch_in(folder: str):
The command "git branch" is called in the given folder and the The command "git branch" is called in the given folder and the
output is returned output is returned
""" """
with tempfile.NamedTemporaryFile(delete=False, mode="w") as t: with tempfile.NamedTemporaryFile(delete=False, mode="w") as tempf:
call(["git", "rev-parse", "--abbrev-ref", "HEAD"], stdout=t, cwd=folder) call(["git", "rev-parse", "--abbrev-ref", "HEAD"], stdout=tempf, cwd=folder)
with open(t.name, "r") as t: with open(tempf.name, "r") as t:
return t.readline().strip() return t.readline().strip()
...@@ -76,7 +76,7 @@ def get_commit_in(folder: str): ...@@ -76,7 +76,7 @@ def get_commit_in(folder: str):
and the output is returned and the output is returned
""" """
with tempfile.NamedTemporaryFile(delete=False, mode="w") as t: with tempfile.NamedTemporaryFile(delete=False, mode="w") as tempf:
call(["git", "log", "-1", "--format=%h"], stdout=t, cwd=folder) call(["git", "log", "-1", "--format=%h"], stdout=tempf, cwd=folder)
with open(t.name, "r") as t: with open(tempf.name, "r") as t:
return t.readline().strip() return t.readline().strip()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment