Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add input type-checking to Commands #190

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

shartse
Copy link

@shartse shartse commented Feb 26, 2020

Pull request checklist

Please check if your PR fulfills the following requirements:

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been reviewed and added / updated if needed (for bug fixes / features)
  • Build was run locally and any changes were pushed
  • Lint has passed locally and any fixes were made for failures

Pull request type

Please check the type of change your PR introduces:

  • Bugfix
  • Feature
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Documentation content changes
  • Other (please describe):

What is the current behavior?

Issue Number: #159

What is the new behavior?

Refactored the input-type checking to be a generator and added it to the generic Command implementation.

Note - because we actually support multiple input and output types for certain commands (spa and vdev), I added extra logic to check for InputHandler functionality. This might not be the cleanest solution - maybe exact command should have a Set for input and output types instead of a single string? Maybe we want to revisit the idea of multiple input/output types at all?

Does this introduce a breaking change?

  • Yes
  • No

Other information

sdb/command.py Outdated Show resolved Hide resolved
sdb/command.py Outdated Show resolved Hide resolved
sdb/command.py Outdated Show resolved Hide resolved
sdb/command.py Outdated
@@ -240,6 +240,29 @@ def _call(self,
"""
raise NotImplementedError()

def __input_type_check(
self, objs: Iterable[drgn.Object]) -> Iterable[drgn.Object]:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that this also needs to accept any walkable type, at least for Locator's. see Locator.caller(). How much benefit do Locator's get from this new checking? If not much, then I think only non-Locator, non-PrettyPrinter commands would be getting new checking (of which there are not very many). Note that Walker also has this checking built in, but that could be removed in favor of the Command type-checking.

Copy link
Contributor

@sdimitro sdimitro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add some examples in the test suite that make sure that Walkers and Locators can still be passed things like void * and still work after this change?

e.g.

sdb> addr spa_namespace_avl | cast void * | avl | spa
ADDR               NAME
------------------------------------------------------------
0xffff944eccfd4000 rpool

@shartse shartse changed the title Refactor PrettyPrinter type-checking and extend it to all commands Add input type-checking to Commands Mar 9, 2020
@prachetaa
Copy link

Codecov Report

Merging #190 into master will increase coverage by 0.26%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #190      +/-   ##
==========================================
+ Coverage   85.36%   85.62%   +0.26%     
==========================================
  Files          56       56              
  Lines        2309     2324      +15     
==========================================
+ Hits         1971     1990      +19     
+ Misses        338      334       -4     
Impacted Files Coverage Δ
sdb/commands/pretty_print.py 65.21% <ø> (ø)
sdb/command.py 76.45% <100.00%> (+3.06%) ⬆️
sdb/commands/linux/per_cpu.py 96.96% <0.00%> (-3.04%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0ea73b6...f304dc8. Read the comment docs.

cur_type != prev_type):
raise CommandError(
self.name,
f'expected input of type {self.input_type}, but received '
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like this should be printing valid_input_types, rather than self.input_type

@@ -281,15 +304,19 @@ def call(self, objs: Iterable[drgn.Object]) -> Iterable[drgn.Object]:
# the command is running.
#
try:
result = self._call(objs)
if self.input_type and objs:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are subclasses allowed to have input_type=None but _valid_input_types() is not the empty set? I think this should be the case for Walk() and PrettyPrint().

@ahrens
Copy link
Contributor

ahrens commented Apr 15, 2020

I think that Walker._call() also needs to be updated to do the input type checking correctly. It's currently using type equality, which doesn't work at all. We'll at least need to use the canonicalized type names.

@dlpx-tfc-github-manager dlpx-tfc-github-manager bot deleted the branch delphix:master January 5, 2023 22:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants