[v16,2/5] dts: replace the or operator in third party types

Message ID 20240808085452.426702-3-juraj.linkes@pantheon.tech (mailing list archive)
State Superseded
Delegated to: Juraj Linkeš
Headers
Series API docs generation |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Juraj Linkeš Aug. 8, 2024, 8:54 a.m. UTC
When the DTS dependencies are not installed when building DTS API
documentation, the or operator produces errors when used with types from
those libraries:
autodoc: failed to import module 'remote_session' from module
'framework'; the following exception was raised:
Traceback (most recent call last):
...
TypeError: unsupported operand type(s) for |: 'Transport' and 'NoneType'

The third part type here is Transport from the paramiko library.

Signed-off-by: Juraj Linkeš <juraj.linkes@pantheon.tech>
---
 dts/framework/remote_session/interactive_remote_session.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
  

Comments

Jeremy Spewock Aug. 9, 2024, 7:03 p.m. UTC | #1
This is a funny change I wouldn't have expected the series to need. I
don't doubt that it does need it of course and I don't think there is
any harm in the change, but, out of curiosity, is this because the or
operator is coming from one of the dependencies we are installing? I
thought it was just shipped with later Python versions. Regardless,

Reviewed-by: Jeremy Spewock <jspewock@iol.unh.edu>
  
Juraj Linkeš Aug. 12, 2024, 7:58 a.m. UTC | #2
On 9. 8. 2024 21:03, Jeremy Spewock wrote:
> This is a funny change I wouldn't have expected the series to need. I
> don't doubt that it does need it of course and I don't think there is
> any harm in the change, but, out of curiosity, is this because the or
> operator is coming from one of the dependencies we are installing? I
> thought it was just shipped with later Python versions. Regardless,

I think this happens when Paramiko is not installed, as is likely the 
case in CI. When Paramiko is installed, the issue doesn't crop up.

I added the autodoc_mock_imports [0] configuration so that dependencies 
don't have to be installed. I don't know how exactly autodoc gets around 
the imports, but that seems to be what's causing the error when Paramiko 
is missing.

[0] 
https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html#confval-autodoc_mock_imports

> 
> Reviewed-by: Jeremy Spewock <jspewock@iol.unh.edu>
  

Patch

diff --git a/dts/framework/remote_session/interactive_remote_session.py b/dts/framework/remote_session/interactive_remote_session.py
index 97194e6af8..4605ee14b4 100644
--- a/dts/framework/remote_session/interactive_remote_session.py
+++ b/dts/framework/remote_session/interactive_remote_session.py
@@ -5,6 +5,7 @@ 
 
 import socket
 import traceback
+from typing import Union
 
 from paramiko import AutoAddPolicy, SSHClient, Transport  # type: ignore[import-untyped]
 from paramiko.ssh_exception import (  # type: ignore[import-untyped]
@@ -52,7 +53,7 @@  class InteractiveRemoteSession:
     session: SSHClient
     _logger: DTSLogger
     _node_config: NodeConfiguration
-    _transport: Transport | None
+    _transport: Union[Transport, None]
 
     def __init__(self, node_config: NodeConfiguration, logger: DTSLogger) -> None:
         """Connect to the node during initialization.