Skip to content

Tidy up the last few Ruff problems in one_shot.py - #160

Merged
rswarbrick merged 1 commit into
lowRISC:masterfrom
rswarbrick:one-shot-ruff-tweaks
Apr 7, 2026
Merged

rswarbrick merged 1 commit into
lowRISC:masterfrom
rswarbrick:one-shot-ruff-tweaks

Conversation

@rswarbrick

Copy link
Copy Markdown
Contributor

No description provided.

"""Simple one-shot build flow for non-simulation targets like linting, synthesis and FPV."""

ignored_wildcards = [*FlowCfg.ignored_wildcards, "build_mode", "index", "test"]
ignored_wildcards: ClassVar[list[str]] = [

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Aside (you don't need to change it in this PR, it just came to mind as I looked at the code):

It needs a more careful examination, but it looks to me like FlowCfg.ignored_wildcards is only used in its _expand stage (with the HJSON __dict__ replacement magic). That is, I think this class attribute is set once and never mutated (even by the HJSON). If that is the case then this should probably be converted to a ClassVar[tuple[str, ...]] to remove the mutability. Either way the ClassVar type is reasonable here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think that's probably a good idea (and, as you say, probably for a different PR)

Comment thread src/dvsim/flow/one_shot.py Resolved
Comment thread src/dvsim/flow/one_shot.py Resolved
@rswarbrick
rswarbrick force-pushed the one-shot-ruff-tweaks branch from e511810 to 5b08ad7 Compare April 4, 2026 18:12
@rswarbrick

Copy link
Copy Markdown
Contributor Author

@AlexJones0: Thanks for the review. I've addressed things, but it was a bit more typing than I expected. Accessing the function properly means that Ruff (correctly) points out that we probably shouldn't be calling a private function. All fixed now though, I think.

@rswarbrick
rswarbrick requested a review from AlexJones0 April 4, 2026 18:15

@machshev machshev left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nice to see the linting being tidied up, thanks @rswarbrick!
Just a nit about the new public method.

Comment thread src/dvsim/flow/one_shot.py Outdated
]

result = item._gen_results(item_results)
result = item.gen_results_for_cfg(item_results)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'd leave this private at add a Ruff exclusion to this line. This creates a public method that is only called internally, which I think is worse as we should only create public methods if we plan on supporting the public interface long term. I can't see any reason to, and it makes refactoring more difficult later.

This Ruff rule is to prevent people depending on private methods or attributes of objects they don't own. Which is sensible as if you do this on a third party library it could easily break if the internals are refactored. Here the concern doesn't apply as we have ownership of the method and all it's callers.

While Ruff is technically correct in that it is bad practice and highlights a bigger design issue. I think the real issue is the inheritance model and perhaps the typing of item.

So I'd suggest leaving it private for the moment, add a linting exception to the line and we can refactor later to resolve the underlying issues?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think I agree. I've rejigged things and I think it should look better now?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks!

The biggest change is renaming _gen_results to _gen_results_for_cfg.
This was originally inspired by me dropping the '_' prefix to avoid
what the Ruff tool reports as an external use of a private method.
At that point, the names needed de-duplicating.

Since this isn't *really* an external use, we've put the underscore
back and added a noqa line to explain to Ruff that we've thought about
it. But I think the more specific name for the "just this cfg"
function is probably a good idea, so I've kept that.

Signed-off-by: Rupert Swarbrick <rswarbrick@lowrisc.org>
@rswarbrick
rswarbrick force-pushed the one-shot-ruff-tweaks branch from 5b08ad7 to 46af1c6 Compare April 6, 2026 21:05
@rswarbrick
rswarbrick requested a review from machshev April 6, 2026 21:06

@machshev machshev left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks @rswarbrick

@rswarbrick
rswarbrick added this pull request to the merge queue Apr 7, 2026
Merged via the queue into lowRISC:master with commit b2de3fc Apr 7, 2026
6 checks passed
@rswarbrick
rswarbrick deleted the one-shot-ruff-tweaks branch April 7, 2026 17:16
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.

3 participants