Skip to content

Commit

Permalink
docs: remove type hints from docstrings (#94)
Browse files Browse the repository at this point in the history
Closes #40

### Summary of Changes

We've had a few cases in the past where type hints in the docs and in
the code disagreed. Unfortunately, PyCharm prefers the types in the docs
in this case, leading to confusion. Now, only the code contains type
hints.
  • Loading branch information
lars-reimann authored Apr 23, 2024
1 parent 562ad8e commit e9660f7
Show file tree
Hide file tree
Showing 8 changed files with 151 additions and 145 deletions.
4 changes: 2 additions & 2 deletions src/safeds_runner/server/_json_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ def default(self, o: Any) -> Any:
Parameters
----------
o: Any
o:
An object that needs to be encoded to JSON.
Returns
-------
Any
json_serializable:
The passed object represented in a way that is serializable to JSON.
"""
# Moving these imports to the top drastically increases startup time
Expand Down
43 changes: 23 additions & 20 deletions src/safeds_runner/server/_memoization_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ def __init__(
Parameters
----------
map_values
map_values:
Value store dictionary
map_stats
map_stats:
Stats dictionary
"""
self._map_values: dict[MemoizationKey, Any] = map_values
Expand All @@ -54,7 +54,8 @@ def get_cache_size(self) -> int:
Returns
-------
Amount of bytes, this cache occupies. This may be an estimate.
cache_size:
Amount of bytes, this cache occupies. This may be an estimate.
"""
return functools.reduce(
operator.add,
Expand All @@ -70,7 +71,7 @@ def ensure_capacity(self, needed_capacity: int) -> None:
Parameters
----------
needed_capacity
needed_capacity:
Amount of free storage space requested, in bytes
"""
if self.max_size is None:
Expand All @@ -86,7 +87,7 @@ def remove_worst_element(self, capacity_to_free: int) -> None:
Parameters
----------
capacity_to_free
capacity_to_free:
Amount of bytes that should be additionally freed, after this function returns
"""
copied_stats = list(self._map_stats.copy().items())
Expand Down Expand Up @@ -126,18 +127,19 @@ def memoized_function_call(
Parameters
----------
function_name
function_name:
Fully qualified function name
function_callable
function_callable:
Function that is called and memoized if the result was not found in the memoization map
parameters
parameters:
List of parameters passed to the function
hidden_parameters
hidden_parameters:
List of hidden parameters for the function. This is used for memoizing some impure functions.
Returns
-------
The result of the specified function, if any exists
result:
The result of the specified function, if any exists
"""
access_timestamp = time.time_ns()

Expand Down Expand Up @@ -198,12 +200,13 @@ def _lookup_value(self, key: MemoizationKey) -> Any | None:
Parameters
----------
key
key:
Memoization Key
Returns
-------
The value corresponding to the provided memoization key, if any exists.
value:
The value corresponding to the provided memoization key, if any exists.
"""
looked_up_value = self._map_values.get(key)
return _unwrap_value_from_shared_memory(looked_up_value)
Expand All @@ -214,11 +217,11 @@ def _update_stats_on_hit(self, function_name: str, access_timestamp: int, lookup
Parameters
----------
function_name
function_name:
Fully qualified function name
access_timestamp
access_timestamp:
Timestamp when this value was last accessed
lookup_time
lookup_time:
Duration the comparison took in nanoseconds
"""
stats = self._map_stats[function_name]
Expand All @@ -241,15 +244,15 @@ def _update_stats_on_miss(
Parameters
----------
function_name
function_name:
Fully qualified function name
access_timestamp
access_timestamp:
Timestamp when this value was last accessed
lookup_time
lookup_time:
Duration the comparison took in nanoseconds
computation_time
computation_time:
Duration the computation of the new value took in nanoseconds
memory_size
memory_size:
Memory the newly computed value takes up in bytes
"""
stats = self._map_stats.get(function_name)
Expand Down
23 changes: 12 additions & 11 deletions src/safeds_runner/server/_memoization_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ class MemoizationStats:
Parameters
----------
access_timestamps
access_timestamps:
Absolute timestamp since the unix epoch of the last access to the memoized value in nanoseconds
lookup_times
lookup_times:
Duration the lookup of the value took in nanoseconds (key comparison + IPC)
computation_times
computation_times:
Duration the computation of the value took in nanoseconds
memory_sizes
memory_sizes:
Amount of memory the memoized value takes up in bytes
"""

Expand All @@ -32,9 +32,9 @@ def update_on_hit(self, access_timestamp: int, lookup_time: int) -> None:
Parameters
----------
access_timestamp
access_timestamp:
Timestamp when this value was last accessed
lookup_time
lookup_time:
Duration the comparison took in nanoseconds
"""
self.access_timestamps.append(access_timestamp)
Expand All @@ -46,13 +46,13 @@ def update_on_miss(self, access_timestamp: int, lookup_time: int, computation_ti
Parameters
----------
access_timestamp
access_timestamp:
Timestamp when this value was last accessed
lookup_time
lookup_time:
Duration the comparison took in nanoseconds
computation_time
computation_time:
Duration the computation of the new value took in nanoseconds
memory_size
memory_size:
Memory the newly computed value takes up in bytes
"""
self.access_timestamps.append(access_timestamp)
Expand All @@ -66,7 +66,8 @@ def __str__(self) -> str:
Returns
-------
Summary of stats
string_representation:
Summary of stats
"""
return ( # pragma: no cover
f"Last access: {self.access_timestamps}, computation time: {self.computation_times}, lookup time:"
Expand Down
Loading

0 comments on commit e9660f7

Please sign in to comment.