-
Notifications
You must be signed in to change notification settings - Fork 38.7k
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
Test: use new intstr functions #117631
Test: use new intstr functions #117631
Conversation
Hi @skitt. Thanks for your PR. I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
/triage accepted |
This touches cases where FromInt() is used on numeric constants, or values which are already int32s, or int variables which are defined close by and can be changed to int32s with little impact. Signed-off-by: Stephen Kitt <skitt@redhat.com>
d332970
to
3418cea
Compare
3418cea
to
d332970
Compare
d332970
to
3418cea
Compare
Can you remind me why we didn't just change the original FromInt() to int32? It's not a public API. |
I’m not sure it would have been tractable for me to convert everything in one PR (just from a review perspective; although at least in this PR most of the changes would have become unnecessary). It also turned out to be useful to keep the |
I think it would be cleaner to call What about generics? something like: https://go.dev/play/p/noMl3HAd1h_z Since it is internal, this seems legit to me. |
Ah, digging into this some more I remember one of the concerns I had — the overflow check in https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/apimachinery/pkg/util/intstr/intstr.go#L59 means that a plain I like the generic approach to handle all smaller types, and I agree |
This is an internal API - we can either change it and disallow anything larger than int32 via the type system or we can keep the (gross) range check, but that's really a vestigial artifact from pre-generic days. |
I’ve done this as #119285, without using generics for two reasons — there are no users of |
How often do we need to use literals? If we use generics you need to cast literals and almost nothing else. If we don't use generics we have to cast almost everywhere, including literals. Why is it better to not use generics? |
105 times in the current code-base. (#119285 leaves 10 casts from non-literals.) With the suggested generics, type smallInt interface {
int8 | int16 | int32
} most current uses of non-literals need to be cast anyway (from (The code produced for generics isn’t great, see https://godbolt.org/z/WrK57rcP3, but that’s probably not worth worrying about here compared to the convenience factor.) |
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.
Thanks!
/lgtm
/approve
LGTM label has been added. Git tree hash: 49c40d31e22bc614db98ba6c3b361a1b65317766
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: skitt, thockin The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
What type of PR is this?
/kind cleanup
What this PR does / why we need it:
#116665 introduces
intstr
contructors fromint32
; this PR updates code to use them./hold pending #116665
Which issue(s) this PR fixes:
Special notes for your reviewer:
Does this PR introduce a user-facing change?
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.: