Closed Bug 1804442 Opened 1 year ago Closed 1 year ago

Use the Enum objects as dictionary keys directly instead of the string value

Categories

(Testing :: Performance, task, P2)

task

Tracking

(Not tracked)

RESOLVED WONTFIX

People

(Reporter: sparky, Unassigned)

References

(Blocks 1 open bug)

Details

After bug 1803361 lands, we'll have Enum classes for all of our settings. These are special enum classes (ClassificationEnum) that allow us to use them as indices to arrays/matrices and also store a string-value representation.

We access the string element with enum.CLASSIFICATION.value but in many places in the code we could simply use enum.CLASSIFICATION. We should see if we can replace the usages to get rid of the .value.

I tried to get rid of the .value attribute[0] in some ways. (There is one in the link[0], But We should remove all .value)
I couldn't fix it in the following way.

  1. I used the __str__ (or __repr__) method as follow:
class ClassificationEnum(enum.Enum): 
+    def __str__(self):
+        return self.value
 
class Platforms(ClassificationEnum):
      platforms = {
-        Platforms.ANDROID_A51.value: {
+        Platforms.ANDROID_A51: {

It's not working well. Platforms.ANDROID_A51.value is str type. But Platforms.ANDROID_A51 type is Platforms class type.
If I use this method, I should cover the str() to all the enums(e.g, str(Platforms.ANDROID_A51)).
This isn't the way we want it to be.

  1. I used the str mixin in the ClassificationEnum as follows:
-class ClassificationEnum(enum.Enum):
+class ClassificationEnum(str, enum.Enum):
     @property
     def value(self):
-        return self._value_["value"]
+        return eval(self._value_)["value"]
 
     def __index__(self):
-        return self._value_["index"]
+        return eval(self._value_)["index"]
 
     def __int__(self):
-        return self._value_["index"]
+        return eval(self._value_)["index"]

+    def __str__(self):
+        return self.value

class Platforms(ClassificationEnum):
     platforms = {
-        Platforms.ANDROID_A51.value: {
+        Platforms.ANDROID_A51: {

I'd like to make the enum(e.g, Platforms.ANDROID_A51) to the str type.
In this way, It is same necessary to cover the str()(e.g, str(Platforms.ANDROID_A51)).

[0]
https://searchfox.org/mozilla-central/rev/3002762e41363de8ee9ca80196d55e79651bcb6b/tools/tryselect/selectors/perf.py#177

Status: NEW → RESOLVED
Closed: 1 year ago
Resolution: --- → WONTFIX
You need to log in before you can comment on or make changes to this bug.