nion-software / nionswift-instrumentation-kit

Base classes for Nion Swift STEM microscope instrumentation
GNU General Public License v3.0
1 stars 12 forks source link

Drift scan customization #135

Closed Brow71189 closed 2 years ago

Brow71189 commented 2 years ago

Add restore defaults button to drift frame parameters settings. Reset drift frame parameters to defaults on restart of Swift.

Brow71189 commented 2 years ago

I do not understand what is going on with mypy here: The error is saying that AcquisitionPreferences.py:217: error: Argument 2 to "create" of "EntityType" has incompatible type "Dict[str, float]"; expected "Optional[Dict[str, Union[Dict[str, Any], List[Any], Tuple[Any], str, float, int, bool, None]]]. But isn't Dict[str, float] exactly included in the argument type?

Also, when I run type checking with mypy on my local machine, I get 76 errors that do not show up in the CI, but I do NOT get the error that shows up in the CI. I'm using the exact same mypy version (0.971) and python 3.9.13. I'm also always copying the type checking line from the github workflows file to ensure that I'm getting the same results. @cmeyer , do you have any idea what is going on there?

Here are the errors I'm getting when type checking this pull request.

nion\instrumentation\AcquisitionPreferences.py:19: error: Class cannot subclass "Observable" (has type "Any")
nion\instrumentation\AcquisitionPreferences.py:86: error: Class cannot subclass "Entity" (has type "Any")
nion\instrumentation\AcquisitionPreferences.py:142: error: Class cannot subclass "RecorderLogger" (has type "Any")
nion\instrumentation\AcquisitionPreferences.py:180: error: Class cannot subclass "Entity" (has type "Any")
nion\instrumentation\HardwareSource.py:912: error: Class cannot subclass "Observable" (has type "Any")
nion\instrumentation\HardwareSource.py:1442: error: Class cannot subclass "Observable" (has type "Any")
nion\instrumentation\HardwareSource.py:1843: error: Returning Any from function declared to return "bool"
nionswift_plugin\nion_instrumentation_ui\HardwareSourceChoice.py:102: error: Class cannot subclass value of type "Any"
nion\instrumentation\Acquisition.py:403: error: Class cannot subclass "ReferenceCounted" (has type "Any")
nion\instrumentation\Acquisition.py:1428: error: Class cannot subclass "ReferenceCounted" (has type "Any")
nion\instrumentation\Acquisition.py:1518: error: Class cannot subclass "ReferenceCounted" (has type "Any")
nion\instrumentation\Acquisition.py:1637: error: Returning Any from function declared to return "str"
nionswift_plugin\nion_instrumentation_ui\VideoControlPanel.py:298: error: Class cannot subclass "CompositeWidgetBase" (has type "Any")
nionswift_plugin\nion_instrumentation_ui\VideoControlPanel.py:357: error: Class cannot subclass "Panel" (has type "Any")
nionswift_plugin\nion_instrumentation_ui\VideoControlPanel.py:413: error: Class cannot subclass "Handler" (has type "Any")
nionswift_plugin\nion_instrumentation_ui\VideoControlPanel.py:425: error: Class cannot subclass "Handler" (has type "Any")
nion\instrumentation\stem_controller.py:172: error: Class cannot subclass "Observable" (has type "Any")
nion\instrumentation\stem_controller.py:702: error: Class cannot subclass "Observable" (has type "Any")
nion\instrumentation\stem_controller.py:828: error: Class cannot subclass "AbstractImplicitDependency" (has type "Any")
nion\instrumentation\stem_controller.py:917: error: Class cannot subclass "AbstractImplicitDependency" (has type "Any")
nion\instrumentation\stem_controller.py:1019: error: Class cannot subclass "AbstractImplicitDependency" (has type "Any")
nion\instrumentation\camera_base.py:1567: error: Returning Any from function declared to return "Dict[str, Any]"
nion\instrumentation\scan_base.py:1517: error: Returning Any from function declared to return "float"
nionswift_plugin\nion_instrumentation_ui\ScanControlPanel.py:671: error: Class cannot subclass "TextButtonCanvasItem" (has type "Any")
nionswift_plugin\nion_instrumentation_ui\ScanControlPanel.py:782: error: Class cannot subclass "TextButtonCanvasItem" (has type "Any")
nionswift_plugin\nion_instrumentation_ui\ScanControlPanel.py:870: error: Class cannot subclass "AbstractCanvasItem" (has type "Any")
nionswift_plugin\nion_instrumentation_ui\ScanControlPanel.py:894: error: Returning Any from function declared to return "str"
nionswift_plugin\nion_instrumentation_ui\ScanControlPanel.py:988: error: Class cannot subclass "CheckBoxCanvasItem" (has type "Any")
nionswift_plugin\nion_instrumentation_ui\ScanControlPanel.py:1021: error: Class cannot subclass "CompositeWidgetBase" (has type "Any")
nionswift_plugin\nion_instrumentation_ui\ScanControlPanel.py:1529: error: Returning Any from function declared to return "None"
nionswift_plugin\nion_instrumentation_ui\ScanControlPanel.py:1530: error: Returning Any from function declared to return "None"
nionswift_plugin\nion_instrumentation_ui\ScanControlPanel.py:1531: error: Returning Any from function declared to return "None"
nionswift_plugin\nion_instrumentation_ui\ScanControlPanel.py:1601: error: Class cannot subclass "Panel" (has type "Any")
nionswift_plugin\nion_instrumentation_ui\ScanControlPanel.py:1861: error: Class cannot subclass "Handler" (has type "Any")
nionswift_plugin\nion_instrumentation_ui\CameraControlPanel.py:358: error: Class cannot subclass "TextButtonCanvasItem" (has type "Any")
nionswift_plugin\nion_instrumentation_ui\CameraControlPanel.py:469: error: Class cannot subclass "TextButtonCanvasItem" (has type "Any")
nionswift_plugin\nion_instrumentation_ui\CameraControlPanel.py:588: error: Class cannot subclass "CompositeWidgetBase" (has type "Any")
nionswift_plugin\nion_instrumentation_ui\CameraControlPanel.py:949: error: Class cannot subclass "Panel" (has type "Any")
nionswift_plugin\nion_instrumentation_ui\MultiAcquirePanel.py:142: error: Returning Any from function declared to return "Optional[CameraHardwareSource]"
nionswift_plugin\nion_instrumentation_ui\MultiAcquirePanel.py:747: error: Class cannot subclass "ActionDialog" (has type "Any")
nionswift_plugin\nion_instrumentation_ui\MultipleShiftEELSAcquire.py:374: error: Class cannot subclass "Panel" (has type "Any")
nionswift_plugin\nion_instrumentation_ui\AcquisitionPanel.py:83: error: Class cannot subclass "Handler" (has type "Any")
nionswift_plugin\nion_instrumentation_ui\AcquisitionPanel.py:94: error: Class cannot subclass "Handler" (has type "Any")
nionswift_plugin\nion_instrumentation_ui\AcquisitionPanel.py:172: error: Class cannot subclass "Handler" (has type "Any")
nionswift_plugin\nion_instrumentation_ui\AcquisitionPanel.py:385: error: Class cannot subclass "Handler" (has type "Any")
nionswift_plugin\nion_instrumentation_ui\AcquisitionPanel.py:794: error: Class cannot subclass "Handler" (has type "Any")
nionswift_plugin\nion_instrumentation_ui\AcquisitionPanel.py:943: error: Class cannot subclass "Handler" (has type "Any")
nionswift_plugin\nion_instrumentation_ui\AcquisitionPanel.py:999: error: Class cannot subclass "Handler" (has type "Any")
nionswift_plugin\nion_instrumentation_ui\AcquisitionPanel.py:1128: error: Class cannot subclass value of type "Any"
nionswift_plugin\nion_instrumentation_ui\AcquisitionPanel.py:1264: error: Class cannot subclass value of type "Any"
nionswift_plugin\nion_instrumentation_ui\AcquisitionPanel.py:1310: error: Returning Any from function declared to return "float"
nionswift_plugin\nion_instrumentation_ui\AcquisitionPanel.py:1323: error: Class cannot subclass "Handler" (has type "Any")
nionswift_plugin\nion_instrumentation_ui\AcquisitionPanel.py:1921: error: Class cannot subclass "Entity" (has type "Any")
nionswift_plugin\nion_instrumentation_ui\AcquisitionPanel.py:1972: error: Class cannot subclass "Handler" (has type "Any")
nionswift_plugin\nion_instrumentation_ui\AcquisitionPanel.py:2082: error: Class cannot subclass "Handler" (has type "Any")
nionswift_plugin\nion_instrumentation_ui\AcquisitionPanel.py:2129: error: Class cannot subclass value of type "Any"
nionswift_plugin\nion_instrumentation_ui\AcquisitionPanel.py:2260: error: Class cannot subclass "Panel" (has type "Any")
nionswift_plugin\nion_instrumentation_ui\AcquisitionPanel.py:2301: error: Returning Any from function declared to return "Sequence[float]"
nionswift_plugin\nion_instrumentation_ui\AcquisitionPanel.py:2389: error: Class cannot subclass "Handler" (has type "Any")
nionswift_plugin\nion_instrumentation_ui\AcquisitionPanel.py:2405: error: Class cannot subclass "Handler" (has type "Any")
nionswift_plugin\nion_instrumentation_ui\DriftCorrectionPanel.py:77: error: Argument "scan_hardware_source" to "SubscanPositionDriftCorrectionMethod" has incompatible type "Optional[ScanHardwareSource]"; expected "ScanHardwareSource"
nionswift_plugin\nion_instrumentation_ui\DriftCorrectionPanel.py:78: error: Item "None" of "Optional[ScanHardwareSource]" has no attribute "get_current_frame_parameters"
nionswift_plugin\nion_instrumentation_ui\DriftCorrectionPanel.py:89: error: Class cannot subclass value of type "Any"
nionswift_plugin\nion_instrumentation_ui\DriftCorrectionPanel.py:109: error: Class cannot subclass value of type "Any"
nionswift_plugin\nion_instrumentation_ui\DriftCorrectionPanel.py:124: error: Class cannot subclass value of type "Any"
nionswift_plugin\nion_instrumentation_ui\DriftCorrectionPanel.py:125: error: Function is missing a return type annotation
nionswift_plugin\nion_instrumentation_ui\DriftCorrectionPanel.py:125: note: Use "-> None" if function does not return a value
nionswift_plugin\nion_instrumentation_ui\DriftCorrectionPanel.py:152: error: Class cannot subclass "ListPropertyModel" (has type "Any")
nionswift_plugin\nion_instrumentation_ui\DriftCorrectionPanel.py:159: error: Returning Any from function declared to return "Sequence[Any]"
nionswift_plugin\nion_instrumentation_ui\DriftCorrectionPanel.py:172: error: Class cannot subclass "Handler" (has type "Any")
nionswift_plugin\nion_instrumentation_ui\DriftCorrectionPanel.py:205: error: Call to untyped function "ChannelStatesToChannelNamesConverter" in typed context
nionswift_plugin\nion_instrumentation_ui\DriftCorrectionPanel.py:208: error: Function is missing a return type annotation
nionswift_plugin\nion_instrumentation_ui\DriftCorrectionPanel.py:209: error: Argument 1 to "get_enabled_channel_states" has incompatible type "Optional[ScanHardwareSource]"; expected "ScanHardwareSource"
nionswift_plugin\nion_instrumentation_ui\DriftCorrectionPanel.py:210: error: Item "None" of "Optional[ScanHardwareSource]" has no attribute "channel_state_changed_event"
nionswift_plugin\nion_instrumentation_ui\DriftCorrectionPanel.py:299: error: Function is missing a return type annotation
nionswift_plugin\nion_instrumentation_ui\DriftCorrectionPanel.py:299: note: Use "-> None" if function does not return a value
nionswift_plugin\nion_instrumentation_ui\DriftCorrectionPanel.py:303: error: Missing type parameters for generic type "typing.Callable"
nionswift_plugin\nion_instrumentation_ui\DriftCorrectionPanel.py:359: error: Class cannot subclass "Panel" (has type "Any")
Found 76 errors in 14 files (checked 24 source files)
cmeyer commented 2 years ago

This is due to the mypy / setuptools issue and was address in 25eeea2530932e58f80c1a371298ffdf9a85a26d.

Can you rebase this PR and force push to its branch?

Brow71189 commented 2 years ago

This is due to the mypy / setuptools issue and was address in 25eeea2.

Can you rebase this PR and force push to its branch?

That does not seem to be the issue here. If you look at the branch I'm working on here you'll see that test_requirements.txt already includes the fix for the other issue: https://github.com/Brow71189/nionswift-instrumentation-kit/blob/drift_scan_customization/test-requirements.txt

I at least managed to figure out why I got so many failures locally: I did not have all the nion packages installed in the environment I use for running mypy. That works now.

However the one test failure also appearing in the CI stays. Mypy links the following page in the error message: https://mypy.readthedocs.io/en/stable/common_issues.html#variance There they suggest to use immutable types for annotation functions, in out case this means that EntityType.create should take a typing.Mapping instead of typing.Dict as an argument. I tried it locally and it does indeed fix the typing error. No the question is whether this is that a good solution? Maybe it causes problems in different places because this argument is now typed as an immutable mapping.

cmeyer commented 2 years ago

This PR is merged here: c0a5930fa839e07c4b454ad1f7612665677ac1c3