Skip to content

Add type hints for device_protocol.py#437

Merged
marmarek merged 1 commit intoQubesOS:mainfrom
hippalectryon-0:typing-config
Mar 15, 2026
Merged

Add type hints for device_protocol.py#437
marmarek merged 1 commit intoQubesOS:mainfrom
hippalectryon-0:typing-config

Conversation

@hippalectryon-0
Copy link

Follows #436

Comment:

  • the function qbool has nothing to do with device_protocol intrinsically, and is never used within - it's used in backup/core3.py as device_protocol.qbool. I believe it should be moved elsewhere (either inside core3.py or in some util / lib / misc file)

@codecov
Copy link

codecov bot commented Feb 28, 2026

Codecov Report

❌ Patch coverage is 96.05263% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 76.30%. Comparing base (3c1adef) to head (1efaa45).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
qubesadmin/utils.py 70.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #437      +/-   ##
==========================================
+ Coverage   76.29%   76.30%   +0.01%     
==========================================
  Files          53       53              
  Lines        9359     9363       +4     
==========================================
+ Hits         7140     7144       +4     
  Misses       2219     2219              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@marmarek
Copy link
Member

  • the function qbool has nothing to do with device_protocol intrinsically

It used to be used here, but not anymore (since 4102157). I agree, should be moved.

@hippalectryon-0
Copy link
Author

Do you want me to move it in this PR ? If so what would be the appropriate destination ?

@ben-grande
Copy link
Contributor

Do you want me to move it in this PR ? If so what would be the appropriate destination ?

qubesadmin.utils.

@hippalectryon-0 hippalectryon-0 force-pushed the typing-config branch 3 times, most recently from b244545 to 61179e4 Compare March 4, 2026 23:46
@marmarek
Copy link
Member

PipelineRetry

@marmarek
Copy link
Member

I'd like to merge #442 first (when it will be ready), and then I'd ask you to rebase (which would be useful anyway, since some commits from other PRs here are outdated.

@marmarek marmarek merged commit 1efaa45 into QubesOS:main Mar 15, 2026
5 checks passed
@hippalectryon-0 hippalectryon-0 deleted the typing-config branch March 15, 2026 04:15
marmarek added a commit that referenced this pull request Mar 15, 2026
* origin/pr/438:
  handle case where arg is None
  add type hints for app.py

Pull request description:

Follows #437

* `_vm_list` is no a list - it's a dict. I renamed it accordingly.
* I added a new `_vm_dict_initialized` variable that explicitly tracks the initialisation rather than relying on `is None`. (which avoids putting `assert is not None` everywhere)
* (not done in this PR) I believe we should add a comment / docstring to state clearly what's supposed to be in both `_vm_list` and `_vm_objects`. Would be happy to add it to the PR if I get some suggestions.

```python3
def list_deviceclass(self) -> list[str]:
```

I would like to make `deviceclass` a `Literal` list of allowed strings, but I'm not sure what the exhaustive list of allowed classes are ?

* What guarantees below that `volume.name` is not `None` ?

```python3
default_pool = getattr(
                    self.app, "default_pool_" + volume.name, volume.pool
                )
```

* Same for `dst_volume.name` a bit after:
```python3
src_volume = src_vm.volumes[dst_volume.name]
```

* in `qubesd_call` we have
```python3
    def qubesd_call(
        self, dest, method, arg=None, payload=None, payload_stream=None
    ):
        if payload_stream:
            method_path = os.path.join(
                qubesadmin.config.QREXEC_SERVICES_DIR, method
            )
            if not os.path.exists(method_path):
                raise qubesadmin.exc.QubesDaemonCommunicationError(
                    "{} not found".format(method_path)
                )
            command = [
                "env",
                "QREXEC_REMOTE_DOMAIN=dom0",
                "QREXEC_REQUESTED_TARGET=" + dest,
                method_path,
                arg,
            ]
          self._call_with_stream(
                command, payload, payload_stream
            )
```

  * This will fail if `dest=None` but this is not mentioned in the docstring
  * This should also fail if `arg` is `None` since _call_with_stream excepts a `list[str]`, not `list[str|None]`. Is that OK ?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants