Repository navigation
Conversation
Contributor
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: r4victor The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Member
|
/assign @yliaog |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What type of PR is this?
/kind cleanup
What this PR does / why we need it:
The package ships
py.typedsince 37.0.0, but the hand-writtenconfigandutilsmodules are unannotated, so type checkers see their public functions as returningAny(mypy) or inferred partial types (pyright). This PR adds annotations to them without changing behavior.Annotated:
kubernetes.configandkubernetes.aio.config:load_config,load_kube_config,load_kube_config_from_dict,load_incluster_config,list_kube_config_contexts,new_client_from_config,new_client_from_config_dict, and aiorefresh_token.kubernetes.utilsandkubernetes.aio.utils:create_from_directory,create_from_yaml,create_from_dict,create_from_yaml_single_item,FailToCreateError,parse_quantity,get_nodes_metrics,get_pods_metricsandget_pods_metrics_in_all_namespaces.Non-obvious decisions:
config_fileisstr | IO[str] | IO[bytes] | None, sinceKubeConfigMergerreads text and binary file-like objects; the aioconfig_fileisstr | Nonebecause the aio merger only accepts paths.load_configkeyword arguments are typed withUnpackof a privateTypedDictlisting the keys it forwards, so misspelled keywords are reported.temp_file_pathacceptsos.PathLike, since it is only passed toos.makedirsandtempfile.mkstemp.config_dictstays optional where it already defaulted to or acceptedNone; the loaders raiseConfigExceptionfor it at runtime.KubeConfigLoaderthey already return, whichrefresh_tokentakes.dict[str, dict[str, Any]]per namespace forget_pods_metrics_in_all_namespaces) to match their documented shape; the generated custom objects API is typedobjectonly because the endpoint has no response schema.The annotations follow what the code accepts at runtime rather than narrowing it, so code that works today keeps type-checking. The exceptions are inputs that work only incidentally:
parse_quantityacceptsstr | int | float | Decimal, although any object is converted withstr().create_from_yaml(yaml_objects=...)accepts alist, although any non-empty iterable works andNoneentries are skipped.FailToCreateErrortakeslist[ApiException], although any objects withreasonandbodywork.Where
kubernetes-stubscovers these functions (syncconfigonly), the annotations are consistent with it, with these differences:temp_file_pathonload_kube_config,client_configurationonnew_client_from_config, and all ofnew_client_from_config_dict.config_filealso accepts file-like objects, andload_kube_config_from_dictacceptsNoneas described above.list_kube_config_contextsreturnsdict[str, Any]entries instead of the stubs'ContextTypedDict; see the follow-ups below.Which issue(s) this PR fixes:
Part of #2825
Special notes for your reviewer:
Left for follow-ups to keep this PR annotation-only and reviewable:
watchis covered by Watch: add typing information #2744.stream,dynamic,informerandleaderelectionhave return types that depend on arguments (for example_preload_contentinstream), which needs overloads and a separate review.list_kube_config_contextscould returnTypedDicts for kubeconfig context entries, which needs agreeing on how much of the kubeconfig schema to model.create_from_yamlpassesFailToCreateErrors into a newFailToCreateError, whose__str__then fails withAttributeError; sync collects the underlyingApiExceptions instead. Fixing it changes behavior, so it belongs in its own PR.Does this PR introduce a user-facing change?
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.: