Closed dougthor42 closed 1 year ago
I personally prefer to avoid crowding type annotations in init so I would appreciate if you could revert your second commit. Additionally, while we are dealing with linter errors could you address the black issues ?
Done.
Not sure why pre-commit
didn't catch the black
issue... ah well, a problem for another time.
This technically fixes the mypy error seen in
channels.py
, but I'm not sure if it's the best fix. IMO it simply masks the symptom rather than fixes the root cause. I think more refactoring and architecture changes might be needed to fix the root issue.I also move the type hints to
component.Component.__init__
as that's common practice.One of the issues is that the
stringparser
library doesn't have type annotations, so mypy setsparser
toAny
here:https://github.com/pyvisa/pyvisa-sim/blob/b0c22826ad506cc5c5acc155bdca3764dfe14f5e/pyvisa_sim/channels.py#L187
and then
parsed
toAny
here:https://github.com/pyvisa/pyvisa-sim/blob/b0c22826ad506cc5c5acc155bdca3764dfe14f5e/pyvisa_sim/channels.py#L189
From there, the
isinstance
statement end up doing type narrowing toDict[Any, Any]
which then getsUnion
'd withAny
from before.The issue is that the
self.set_value
function doesn't acceptAny
. Based on my (possibly flawed) understanding of the code, it looks like it's safe enough to just convert to a string before callingset_value
. So that's what I do.In addition, I ran a temporary backport of this change to v0.5.1 and ran my tests for a separate project that uses
pyvisa-sim
, and those still ran OK so... I guess it's OK?