Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

small changes to help typing #283

Merged
merged 20 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions spinn_utilities/citation/citation_aggregator.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,8 @@ def _try_to_find_version(imported_module, module_name):
reference_entry = dict()
reference_entry[REFERENCES_TYPE_TYPE] = REFERENCES_SOFTWARE_TYPE
reference_entry[REFERENCES_TITLE_TYPE] = module_name
if imported_module is None:
return reference_entry
if (hasattr(imported_module, "__version_day__") and
hasattr(imported_module, "__version_month__") and
hasattr(imported_module, "__version_year__")):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ class _ZenodoException(Exception):
def __init__(self, operation, expected, request):
super().__init__(
"don't know what went wrong. got wrong status code when trying "
f"to {operation}. Got error code {request.status_code} (when "
f"expecting {expected}) with response content {request.content}")
f"to {operation}. Got error code {request.status_code} "
f"(when expecting {expected}) "
f"with response content {request.content!r}")
self.request = request
self.expected = expected

Expand Down Expand Up @@ -95,7 +96,7 @@ def get_verify(self, related):
r = requests.get(
self._DEPOSIT_GET_URL, timeout=10,
params={self._ACCESS_TOKEN: self.__zenodo_token,
self._RELATED_IDENTIFIERS: related},
self._RELATED_IDENTIFIERS: str(related)},
json={}, headers={self._CONTENT_TYPE: self._JSON})
if r.status_code != self._VALID_STATUS_REQUEST_GET:
raise _ZenodoException(
Expand All @@ -106,7 +107,7 @@ def post_create(self, related):
r = requests.post(
self._DEPOSIT_GET_URL, timeout=10,
params={self._ACCESS_TOKEN: self.__zenodo_token,
self._RELATED_IDENTIFIERS: related},
self._RELATED_IDENTIFIERS: str(related)},
json={}, headers={self._CONTENT_TYPE: self._JSON})
if r.status_code != self._VALID_STATUS_REQUEST_POST:
raise _ZenodoException(
Expand Down
4 changes: 2 additions & 2 deletions spinn_utilities/configs/camel_case_config_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ def optionxform(self, optionstr: str) -> str:
lower = optionstr.lower()
return lower.replace("_", "")

def __init__(self, defaults=None):
super().__init__(defaults)
def __init__(self):
super().__init__()
self._read_files = list()

def read(self, filenames, encoding=None):
Expand Down
32 changes: 0 additions & 32 deletions spinn_utilities/index_is_value.py

This file was deleted.

2 changes: 1 addition & 1 deletion spinn_utilities/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def deepest_parent(parents, child):

# If no match then return None, there is no deepest parent
if match not in parents:
match = None
return None

return match

Expand Down
24 changes: 7 additions & 17 deletions spinn_utilities/make_tools/file_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,26 +96,16 @@ def __call__(self, src, dest, log_file_id, log_database):
#: Number of extra lines written to modified not yet recovered
#: Extra lines are caused by the header and possibly log comment
#: Extra lines are recovered by omitting blank lines
#:
#: :type: int
self._too_many_lines = None
self._too_many_lines: int = -9999999
#: Variables created each time a log method found
#: original c log method found
#:
#: :type: str
self._log = None
self._log: str = "Not yet defined!"
#: Log methods found so far
#:
#: :type: str
self._log_full = None
self._log_full: str = "Not yet defined!"
#: Number of c lines the log method takes
#:
#: :type: int
self._log_lines = None
self._log_lines: int = -9999999
#: Any other stuff found before the log method but on same line
#:
#: :type: str
self._log_start = None
self._log_start: int = -9999999
# variable created when a comment found
#: The previous state
#:
Expand Down Expand Up @@ -412,8 +402,8 @@ def _short_log(self, line_num):
:rtype: str
"""
try:
match = LOG_END_REGEX.search(self._log_full)
main = self._log_full[:-len(match.group(0))]
full_match = LOG_END_REGEX.search(self._log_full)
main = self._log_full[:-len(full_match.group(0))]
except Exception as e:
raise UnexpectedCException(
f"Unexpected line {self._log_full} at "
Expand Down
2 changes: 2 additions & 0 deletions spinn_utilities/make_tools/log_sqllite_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ def set_log_info(
LIMIT 1
""", (log_level, line_num, original, file_id)):
return row["log_id"]
raise ValueError("unexpected no return")

def get_log_info(self, log_id: str) -> Optional[Tuple[int, str, int, str]]:
"""
Expand Down Expand Up @@ -306,3 +307,4 @@ def get_max_log_id(self):
FROM log
"""):
return row["max_id"]
raise ValueError("unexpected no return")
2 changes: 1 addition & 1 deletion spinn_utilities/make_tools/replacer.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def __enter__(self):

def __exit__(self, exc_type, exc_value, exc_traceback):
# nothing yet
pass
return False

_INT_FMT = struct.Struct("!I")
_FLT_FMT = struct.Struct("!f")
Expand Down
2 changes: 1 addition & 1 deletion spinn_utilities/ranged/multiple_values_exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class MultipleValuesException(Exception):
Raised when there more than one value found unexpectedly.
"""

def __init__(self, key=None, value1=None, value2=None):
def __init__(self, key, value1, value2):
if key is None:
msg = "Multiple values found"
else:
Expand Down
21 changes: 11 additions & 10 deletions spinn_utilities/ranged/range_dictionary.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def get_values_by_id(self, key, the_id) -> Union[T, Dict[str, T]]:
if isinstance(key, str):
return self._value_lists[key].get_value_by_id(the_id)
if key is None:
key = self.keys()
key = list(self.keys())
return {
a_key: self._value_lists[a_key].get_value_by_id(the_id)
for a_key in key}
Expand Down Expand Up @@ -428,28 +428,29 @@ def iter_ranges(self, key: _Keys = None) -> \

@overload
def iter_ranges_by_id(
self, key: str, the_id: Optional[int] = None) -> _SimpleRangeIter:
self, *, the_id: int, key: str) -> _SimpleRangeIter:
...

@overload
def iter_ranges_by_id(
self, key: Optional[_StrSeq] = None,
the_id: Optional[int] = None) -> _CompoundRangeIter:
def iter_ranges_by_id(self, *, the_id: int,
key: Optional[_StrSeq] = None) -> _CompoundRangeIter:
...

def iter_ranges_by_id(self, key=None, the_id=None):
def iter_ranges_by_id(
self, *, the_id: int,
key: Union[str, _StrSeq, None] = None) -> Union[
_SimpleRangeIter, _CompoundRangeIter]:
"""
Same as :py:meth:`iter_ranges` but limited to one ID.

:param key: see :py:meth:`iter_ranges` parameter key
:param the_id:
single ID which is the actual ID and not an index into IDs
:type the_id: int
"""
if isinstance(key, str):
return self._value_lists[key].iter_ranges_by_id(the_id=the_id)
if key is None:
key = self.keys()
key = list(self.keys())
return self._merge_ranges({
a_key: self._value_lists[a_key].iter_ranges_by_id(the_id=the_id)
for a_key in key})
Expand Down Expand Up @@ -483,7 +484,7 @@ def iter_ranges_by_slice(self, key, slice_start: int, slice_stop: int):
return self._value_lists[key].iter_ranges_by_slice(
slice_start=slice_start, slice_stop=slice_stop)
if key is None:
key = self.keys()
key = list(self.keys())
return self._merge_ranges({
a_key: self._value_lists[a_key].iter_ranges_by_slice(
slice_start=slice_start, slice_stop=slice_stop)
Expand Down Expand Up @@ -513,7 +514,7 @@ def iter_ranges_by_ids(self, ids: IdsType, key=None):
if isinstance(key, str):
return self._value_lists[key].iter_ranges_by_ids(ids=ids)
if key is None:
key = self.keys()
key = list(self.keys())
return self._merge_ranges({
a_key: self._value_lists[a_key].iter_ranges_by_ids(ids=ids)
for a_key in key})
Expand Down
21 changes: 0 additions & 21 deletions unittests/test_index_is_value.py

This file was deleted.