mirror of
https://github.com/kubernetes/kubernetes.git
synced 2026-02-14 00:07:28 -05:00
Manually pairing Being with End is too error prone to be useful. It had the
advantage of keeping variables created between them visible to the following
code, but that doesn't justify using those calls.
By using a callback we can achieve a few things:
- Code using it automatically shadows the parent tCtx, thus enforcing
that within a code block the tCtx with step is used consistently.
- The code block is clearly delineated with curly braces.
- When the code block ends, the unmodified parent tCtx is automatically
in scope again.
Downsides:
- Extra boilerplate for the anonymous function.
Python's `with tCtx.Step(...) as tCtx: ` would be nicer.
As an approximation of that `for tCtx := range tCtx.Step(...)` was
tried with `Step` returning an iterator, but that wasn't very idiomatic.
- Variables created inside the code block are not visible outside of it.
(cherry picked from commit
|
||
|---|---|---|
| .. | ||
| apiserver | ||
| crd | ||
| fakedns | ||
| format | ||
| harness | ||
| hermeticpodcertificatesigner | ||
| image | ||
| junit | ||
| ktesting | ||
| kubeconfig | ||
| localupcluster | ||
| oidc | ||
| admission_webhook.go | ||
| audit.go | ||
| conditions.go | ||
| create_resources.go | ||
| delete_resources.go | ||
| density_utils.go | ||
| deployment.go | ||
| node.go | ||
| paths.go | ||
| pki_helpers.go | ||
| pod_store.go | ||
| replicaset.go | ||
| runners.go | ||
| tmpdir.go | ||
| update_resources.go | ||