Fix type annotations: replace builtin any with typing.Any#1406
Open
coactive-victor wants to merge 3 commits intodatabricks:mainfrom
Open
Fix type annotations: replace builtin any with typing.Any#1406coactive-victor wants to merge 3 commits intodatabricks:mainfrom
any with typing.Any#1406coactive-victor wants to merge 3 commits intodatabricks:mainfrom
Conversation
Signed-off-by: coactive-victor <victor@coactive.ai>
Occurrences in _internal.py, config.py, dbutils.py, oauth.py, and runtime/dbutils_stub.py were using the builtin any (an Iterable->bool callable) as a type annotation instead of typing.Any. mypy interprets these as the callable type, causing spurious attr-defined errors on annotated values. Signed-off-by: Victor Hugo Xavier <victor@coactive.ai> Signed-off-by: coactive-victor <victor@coactive.ai>
with typing.Any``
with typing.Any``any with typing.Any
Signed-off-by: coactive-victor <victor@coactive.ai>
|
If integration tests don't run automatically, an authorized user can run them manually by following the instructions below: Trigger: Inputs:
Checks will be approved automatically on success. |
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.
Summary
Replaces all uses of the Python builtin
anyas a type annotation withtyping.Anyacross the SDK, fixing incorrect type inference by mypy.Why
anyused as a type annotation refers to the builtin functionany(iterable: Iterable) -> bool, not thetyping.Anywildcard. mypy treats annotated parameters and return values as having the type of that callable, which causes spurious[attr-defined]errors when code accesses attributes on those values at runtime. For example,Wait.responsewas inferred as(Iterable[object]) -> bool, so any attribute access like.run_idwould fail a mypy check even though the code is correct. The fix is mechanical: replace every: any/-> anyannotation withtyping.Any, which is the correct way to express "this value is intentionally untyped."What changed
Interface changes
None.
Behavioral changes
None.
Internal changes
databricks/sdk/service/_internal.py- Fixed_from_dict,_repeated_dict,_enum,_repeated_enum,Wait.__init__, andWait.__getattr__; addedAnyto thetypingimport.databricks/sdk/config.py- FixedConfigAttribute.__set__; addedAnyto thetypingimport.databricks/sdk/dbutils.py- FixedtaskValues.get(×2) andtaskValues.set.databricks/sdk/oauth.py- Fixed thenoop_credentialsparameter annotation.databricks/sdk/runtime/dbutils_stub.py- Fixeddata.summarize,jobs.taskValues.get(×2), andjobs.taskValues.set.How is this tested?
Type-annotation-only change with no behavioral effect. Verified with
black --check(all files pass). A mypy run on code that accesses attributes of annotated values (e.g.Wait.response.run_id) will no longer produce spurious[attr-defined]errors.