chore(refactor): prefer typing.Any to 'object' for type hints #93
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.
Contributes to #87.
Proposes changing type hints using
object
totyping.Any
.This fixes 10 errors from
mypy
.full list (click me)
Notes for Reviewers
What's the difference between
object
andtyping.Any
?I'll let the
typing
docs explain:(docs link)
This is why with a type hint like
object
you get errors like this:typing.Any
tells the type checker "just ignore this object from this point on in the stack".Shouldn't we use a more specific type than
typing.Any
?I don't think so.
These hints with
typing.Any
are only in the parts of the codebase taking in mostly-unstructured data read in withyaml.load()
. Those functions (parse_config()
and the things it calls) are taking on the responsibility of imposing structure and are the only place working with the raw dictionary representation of the YAML.I think it's fairly low-risk to use
typing.Any
in that situation and simpler than, say, creating a type alias with a union of all the types thatyaml.load()
could produce in its dictionary representation of the YAML.pyyaml
's own type stubs usetyping.Any
for the return value ofsafe_load()
: https://github.com/python/typeshed/blob/a9d7e861f7a46ae7acd56569326adef302e10f29/stubs/PyYAML/yaml/__init__.pyi#L38.