Jason Lowe-Power has uploaded this change for review. (
https://gem5-review.googlesource.com/c/public/gem5/+/42644 )
Change subject: python: Improve type annotations in pystats
......................................................................
python: Improve type annotations in pystats
This fixes some errors and warning when running mypy.
`gem5/src/python/m5/ext> mypy pystats`
There is one error that is ignored, which is a bug in mypy. See
https://github.com/python/mypy/issues/6040
Change-Id: I18b648c059da12bd30d612f0e265930b976f22b4
Signed-off-by: Jason Lowe-Power <[email protected]>
---
M src/python/m5/ext/pystats/statistic.py
1 file changed, 13 insertions(+), 12 deletions(-)
diff --git a/src/python/m5/ext/pystats/statistic.py
b/src/python/m5/ext/pystats/statistic.py
index 00d479d..356cc59 100644
--- a/src/python/m5/ext/pystats/statistic.py
+++ b/src/python/m5/ext/pystats/statistic.py
@@ -25,7 +25,7 @@
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
from abc import ABC
-from typing import Any, Optional, Union, List
+from typing import Any, Optional, Union, List, Sequence
from .jsonserializable import JsonSerializable
from .storagetype import StorageType
@@ -74,9 +74,9 @@
"""
An abstract base class for classes containing a vector of Scalar
values.
"""
- value: List[Union[int,float]]
+ value: Sequence[Union[int,float]]
- def __init__(self, value: List[Union[int,float]],
+ def __init__(self, value: Sequence[Union[int,float]],
type: Optional[str] = None,
unit: Optional[str] = None,
description: Optional[str] = None,
@@ -110,12 +110,11 @@
Returns
-------
- float
+ int
The sum of all bin values.
"""
assert(self.value != None)
- assert(isinstance(self.value, List))
- return sum(self.value)
+ return sum(self.value) # type: ignore
class Distribution(BaseScalarVector):
@@ -128,7 +127,6 @@
It is assumed each bucket is of equal size.
"""
- value: List[int]
min: Union[float, int]
max: Union[float, int]
num_bins: int
@@ -139,7 +137,7 @@
overflow: Optional[int]
logs: Optional[float]
- def __init__(self, value: List[int],
+ def __init__(self, value: Sequence[int],
min: Union[float, int],
max: Union[float, int],
num_bins: int,
@@ -179,12 +177,12 @@
A statistical type representing an accumulator.
"""
- count: int
+ _count: int
min: Union[int, float]
max: Union[int, float]
sum_squared: Optional[int]
- def __init__(self, value: List[Union[int,float]],
+ def __init__(self, value: Sequence[Union[int,float]],
count: int,
min: Union[int, float],
max: Union[int, float],
@@ -200,7 +198,10 @@
datatype=datatype,
)
- self.count = count
+ self._count = count
self.min = min
self.max = max
- self.sum_squared = sum_squared
\ No newline at end of file
+ self.sum_squared = sum_squared
+
+ def count(self) -> int:
+ return self._count
--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/42644
To unsubscribe, or for help writing mail filters, visit
https://gem5-review.googlesource.com/settings
Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: I18b648c059da12bd30d612f0e265930b976f22b4
Gerrit-Change-Number: 42644
Gerrit-PatchSet: 1
Gerrit-Owner: Jason Lowe-Power <[email protected]>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s