-
Notifications
You must be signed in to change notification settings - Fork 314
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
Literal check on config section and key by mypy #1798
Literal check on config section and key by mypy #1798
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the idea of using mypy to make sure we covered all config sections/keys. At the same time we don't want to turn this into type hints introduction project for Rally. I don't think the effort is justified. I think we should aim at reducing the scope of this PR to absolute minimum. For instance modifications in esrally/client/synchronous.py
and esrally/client/asynchronous.py
are not relevant, so I think should be reverted.
I've played with this setup a bit and think that if we narrow down mypy to react to arg-type
error only we should achieve the verification we want here, i.e. verification of arguments of config.Config
class methods (see suggestion). If arg-type
error is triggered for anything else than config.Config
methods I would add # type: ignore[arg-type]
annotation.
I've noticed that the list of literals is not complete due to lack of check_untyped_defs = true
option for mypy.
Co-authored-by: Grzegorz Banasiak <[email protected]>
@gbanasiak Thank you for your comments. Please feel free to bring up anything.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the next iteration. I really like the idea with unit tests :)
I did the following sanity check:
% ipython
[..]
In [1]: from esrally.config import Section, Key
In [2]: len(str(Section).split(","))
Out[2]: 21
In [3]: len(str(Key).split(","))
Out[3]: 105
Then in shell:
rg -oN --heading "g\.add\(config\.Scope\..*?, \".*?\", " | grep -Eo "\".*?\"" | sort -u > /tmp/section-tmp.txt
rg -oN --heading "g\.opts\(\".*?\"," | grep -Eo "\".*?\"" | sort -u >> /tmp/section-tmp.txt
sort -u /tmp/section-tmp.txt > /tmp/section.txt
wc -l /tmp/section.txt
rm /tmp/section-tmp.txt
rg -No --heading "g\.add\(config\.Scope\..*?, (\".*?\", ){2}" | awk '{print $3;}' | grep -Eo "\".*?\"" | sort -u > /tmp/key-tmp.txt
rg -oN --heading "g\.opts\(\".*?\)" | awk '{print $2;}' | grep -Eo "\".*?\"" | sort -u >> /tmp/key-tmp.txt
sort -u /tmp/key-tmp.txt > /tmp/key.txt
wc -l /tmp/key.txt
rm /tmp/key-tmp.txt
which produced:
21 /tmp/section.txt
115 /tmp/key.txt
Based on this I think we are right on target with the sections, but some of the keys are still missing. Just as an example (you can reproduce the above for complete list), the first missing key was distribution.dir
which is present in esrally/mechanic/supplier.py
.
Can you revisit the missing keys?
self.coordinator = BenchmarkCoordinator(msg.cfg) | ||
self.coordinator.setup(sources=msg.sources) | ||
self.logger.info("Asking mechanic to start the engine.") | ||
self.mechanic = self.createActor(mechanic.MechanicActor, targetActorRequirements={"coordinator": True}) | ||
self.send( | ||
self.mechanic, | ||
mechanic.StartEngine( | ||
self.cfg, self.coordinator.metrics_store.open_context, msg.sources, msg.distribution, msg.external, msg.docker |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't know why this line has been left until now, but black 23.3.0 reformats it now.
@gbanasiak Here are the highlights in this round. I appreciate a fresh pair of eyes as this PR gets bigger. Thanks.
P.S. Although I wrote “fresh”, I just meant the second pair; not a new pair from someone else. |
git-rebased in the source branch because this PR gets aged. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apologies for delays. This looks good to me. Many thanks for this improvement.
The rebase had broken the diff in GH, but master...sakurai-youhei:literal-check-by-mypy allowed me to see the files that actually changed. I think it might be better to rebase only prior to opening a PR, and then merge master on top of the PR changes.
4095721
to
4693085
Compare
@gbanasiak I didn't notice my git-rebase messed it up. I reverted it instead of appending something more. Thank you very much for your review. I've learned a lot through this PR. I will merge this PR once all the CI checks have passed. |
This PR will introduce a type check by mypy, which helps find illegal literals on the config section and key.
Relates #1646