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

WIP: mypy

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