Skip to content

Conversation

@andrewbwm
Copy link
Contributor

This PR removes the dataclass decorator from two important classes AttackGraphNode and Attacker.

Another major change is that the AttackGraphNode class now requires the id, it is no longer optional. Which in turn means that AttackGraphNodes are now created as they are added to the AttackGraph, analogously to how the ModelAssets are created as they are added to a Model.

@andrewbwm andrewbwm linked an issue Feb 12, 2025 that may be closed by this pull request

def __repr__(self) -> str:
return str(self.to_dict())
return 'LanguageGraphAsset(name: "%s")' % self.name
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a minor thing, but %-formatting is considered clunky, old and less preferred that f-strings and format. Maybe also for consistency it makes sense to stick to one formatting style e.g. f-strings and use format as a backup in cases where f-strings are not suitable?

Copy link
Contributor Author

@andrewbwm andrewbwm Feb 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will at one point lock all of you in a room and when only one sole survivor remains I will just take their advice. I don't remember whom it was that suggested that we switch over to the c-style strings in the debug logs.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a confusing difference I only yesterday came to realize, that you do debug("string %s", var1) and not debug("string %s" % var1). The first does lazy loading (where if the debug function decides it needs to emit sth, it will then proceed with formatting the string), and the second is the same string formatting as if an f-string was used and it will have the same performance issues due to the string being formatted before being passed to the debug function, just for the function to decide not to use it if the log level is higher than debug.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the issue is that you can't do the comma one for strings outside of the methods that know how to handle variable numbers of string parameters. It doesn't matter, I will just add this to the code cleanup issue and we will fix it when we get to it in 2077.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should still use c-style in log statements (for performance). For other cases we might use f-strings if it looks better since it does not affect performance either way.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should still use c-style in log statements (for performance). For other cases we might use f-strings if it looks better since it does not affect performance either way.

The important distinction is that arguments should not be given after a % but as arguments to the logging function.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, maybe c-style is the wrong term, not very used to c.

@andrewbwm andrewbwm merged commit aed8b23 into main Feb 13, 2025
7 checks passed
@andrewbwm andrewbwm deleted the ensure-hash-and-repr branch February 13, 2025 12:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix representation of Asset

4 participants