-
Notifications
You must be signed in to change notification settings - Fork 261
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
convert NamedTuples to @dataclass #38
Comments
If I recall correctly, we favor That said if that causes problems for the wrapper you are writing, we could change this convention. I see that |
Ahh, that's great reasoning. A big part of the project I'm working on is letting users modify generated models such as adding nodes, updating vulnerability descriptions, etc. This would be easier (albeit riskier) to do with mutable Also, |
@jonabox Have you tried the |
Not quite, I ended up changing @dataclass(frozen=True)
class CachedCredential():
"""Encodes a machine-port-credential triplet"""
node: NodeID
port: PortName
credential: CredentialID
def encode(self):
return dataclasses.asdict(self)
cachedCredential = CachedCredential(node="client", port="TCP", credential="TCP-credential" )
json.dumps(cachedCredential, default=lambda x: x.encode())
# returns {"node": "client", "port": "TCP", "credential": "TCP-credential"} I might still try orjson, and get back with any findings, but those slight modifications have worked really well for me so far. |
Hi, I'm creating a frontend wrapper for this project and noticed that NamedTuple and @dataclasses are used almost interchangeably in model.py. I was wondering why that's the case and if it would be possible to just change all NamedTuples to @dataclasses. This would make the model more consistent. I tried changing it for a couple classes and didn't notice anything breaking.
The text was updated successfully, but these errors were encountered: