Add type hints to src/microprobe/code
folder
#38
Merged
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.
This series has a few changes to start integrating type hints into the repo.
Commit 1: Run the yapf command from utils/ensure_style.sh on the
/code
folderCommit 2: Add basic type hints to files in the
/code
folder.Notes:
None
return type. These types may need to change as I understand/annotate more of the code base.**kwargs
patterns to regulararg: type = default
patterns as**kwarg
s are very challenging to type hint. Exampleinit
method gets somewhat verbose.class ClassName(object):
andClassName(six.with_metaclass(abc.ABCMeta, object)):
toclass ClassName:
andclass ClassName(abc.ABC):
@abc.abstractproperty
with@property @abc.abstractmethod
ExampleCommit 3: The facade pattern does not play nicely with python tooling :(
Thankfully an easy workaround is just defining the class methods as an alias on that class.
Commit 4:
get_all_subclasses
does not (and AFAIK cannot) give useful type hints. Because we tightly control the call-site I feel comfortable wrapping the call in a function to provide type information.