Agent-Hellboy / trace-dkey

Python library to trace path of a particular key inside a nested dict
MIT License
7 stars 5 forks source link

Frozen dataclass can be hashable #16

Open Agent-Hellboy opened 1 year ago

Agent-Hellboy commented 1 year ago
from dataclasses import dataclass

@dataclass(frozen=True)
class Data:
    a: int 
    b: int 

data1 = Data(1,2)
print(data1)

dict = {data1: "firstdata"}

print(dict)

For now, we need a different branch to handle this scenario, and as we can assume this one is also _ast.Call object we need to add a new branch for _ast.Call for frozen type which can be hashable

parth-verma7 commented 1 year ago

@Agent-Hellboy Can you please provide with any other example containing multiple dataClasses

Agent-Hellboy commented 1 year ago

@Agent-Hellboy Can you please provide with any other example containing multiple dataClasses

make a new instance of dataclass and pass it inside the dictionary

from dataclasses import dataclass

@dataclass(frozen=True)
class Data:
    a: int
    b: int

data1 = Data(1,2)
data2 = Data(2,3)

dict = {data1: "firstdata",data2:"seconddata"}

print(dict)
parth-verma7 commented 1 year ago

@Agent-Hellboy I would like to work upon this issue. Can you please assign it to me.

Agent-Hellboy commented 1 year ago

sure, go ahead and raise a PR.