-
Notifications
You must be signed in to change notification settings - Fork 154
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
nidaqmx: Fix mypy errors #523
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bkeryan
commented
Mar 1, 2024
zhindes
approved these changes
Mar 2, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lots of great improvements!
generated\nidaqmx\utils.py:78: error: Unsupported operand types for + ("object" and "int") [operator] generated\nidaqmx\utils.py:79: error: Unsupported left operand type for >= ("object") [operator] generated\nidaqmx\utils.py:80: error: Unsupported operand types for - ("object" and "int") [operator] generated\nidaqmx\utils.py:81: error: Unsupported left operand type for <= ("object") [operator]
generated\nidaqmx\scale.py:548: error: Incompatible types in assignment (expression has type "type[Scale]", variable has type "type[_ScaleAlternateConstructor]") [assignment] generated\nidaqmx\system\physical_channel.py:696: error: Incompatible types in assignment (expression has type "type[PhysicalChannel]", variable has type "type[_PhysicalChannelAlternateConstructor]") [assignment]
generated\nidaqmx\_time.py:12: error: Cannot find implementation or library stub for module named "backports" [import-not-found] generated\nidaqmx\_time.py:12: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports generated\nidaqmx\_time.py:12: error: Name "zoneinfo" already defined (by an import) [no-redef]
https://numpy.org/doc/stable/user/basics.types.html says: > Data-types can be used as functions to convert python numbers to array scalars... However, numpy/numpy#23400 says: > Closing for now, as long as the consensus on these types of array-from-scalar constructions remains "do not use; use np.array(..., dtype=...) instead". generated\nidaqmx\system\watchdog.py:244: error: Argument 1 to "floating" has incompatible type "list[Any]"; expected "Union[None, Union[str, bytes], SupportsFloat, SupportsIndex]" [arg-type] generated\nidaqmx\system\watchdog.py:246: error: Argument 1 to "signedinteger" has incompatible type "list[Any]"; expected "Union[SupportsInt, Union[str, bytes], SupportsIndex]" [arg-type] generated\nidaqmx\system\watchdog.py:278: error: Argument 1 to "signedinteger" has incompatible type "list[Any]"; expected "Union[SupportsInt, Union[str, bytes], SupportsIndex]" [arg-type] generated\nidaqmx\system\watchdog.py:310: error: Argument 1 to "signedinteger" has incompatible type "list[Any]"; expected "Union[SupportsInt, Union[str, bytes], SupportsIndex]" [arg-type] generated\nidaqmx\system\system.py:408: error: Argument 1 to "floating" has incompatible type "list[Any]"; expected "Union[None, Union[str, bytes], SupportsFloat, SupportsIndex]" [arg-type] generated\nidaqmx\system\system.py:410: error: Argument 1 to "signedinteger" has incompatible type "list[Any]"; expected "Union[SupportsInt, Union[str, bytes], SupportsIndex]" [arg-type]
generated\nidaqmx\_task_modules\in_stream.py:1063: error: Incompatible types in assignment (expression has type "type[unsignedinteger[Any]]", variable has type "type[signedinteger[Any]]") [assignment] generated\nidaqmx\_task_modules\in_stream.py:1066: error: Incompatible types in assignment (expression has type "type[signedinteger[Any]]", variable has type "type[signedinteger[Any]]") [assignment] generated\nidaqmx\_task_modules\in_stream.py:1068: error: Incompatible types in assignment (expression has type "type[unsignedinteger[Any]]", variable has type "type[signedinteger[Any]]") [assignment] generated\nidaqmx\_task_modules\in_stream.py:1071: error: Incompatible types in assignment (expression has type "type[signedinteger[Any]]", variable has type "type[signedinteger[Any]]") [assignment] generated\nidaqmx\_task_modules\in_stream.py:1073: error: Incompatible types in assignment (expression has type "type[unsignedinteger[Any]]", variable has type "type[signedinteger[Any]]") [assignment]
generated\nidaqmx\stream_readers.py:77: error: Incompatible types in assignment (expression has type "tuple[int]", variable has type "Optional[tuple[int, Any]]") [assignment] generated\nidaqmx\stream_readers.py:80: error: Incompatible types in assignment (expression has type "tuple[Any]", variable has type "Optional[tuple[int, Any]]") [assignment] generated\nidaqmx\stream_readers.py:121: error: Incompatible types in assignment (expression has type "tuple[int]", variable has type "Optional[tuple[int, Any]]") [assignment] generated\nidaqmx\stream_readers.py:124: error: Incompatible types in assignment (expression has type "tuple[Any]", variable has type "Optional[tuple[int, Any]]") [assignment]
`read()` and `write()` had a lot of mypy errors: - `array_shape` is either a tuple of ints or a single int. Change to be a variable-sized tuple of ints. - `data` is a list of named tuples for counter pulse and power, and an ndarray for everything else. Extract `_read_ctr_pulse` and `_read_power` helper methods to clean this up. - `data` and other variables are reused to build lists with for-loops. Convert these to use list comprehensions. - Convert the power meas_type check to use a generator expression. - `numpy.asarray` is for converting values that may already be an ndarray. Use `numpy.array` when the input is definitely not an ndarray. - Add some else cases to catch unexpected meas/output types. generated\nidaqmx\task.py:614: error: Incompatible types in assignment (expression has type "int", variable has type "tuple[int, Any]") [assignment] generated\nidaqmx\task.py:650: error: Argument 1 to "append" of "list" has incompatible type "list[PowerMeasurement]"; expected "PowerMeasurement" [arg-type] generated\nidaqmx\task.py:663: error: Incompatible types in assignment (expression has type "ndarray[Any, dtype[floating[_64Bit]]]", variable has type "list[PowerMeasurement]") [assignment] generated\nidaqmx\task.py:671: error: Incompatible types in assignment (expression has type "ndarray[Any, dtype[Any]]", variable has type "list[PowerMeasurement]") [assignment] generated\nidaqmx\task.py:676: error: Incompatible types in assignment (expression has type "ndarray[Any, dtype[unsignedinteger[_32Bit]]]", variable has type "list[PowerMeasurement]") [assignment] generated\nidaqmx\task.py:694: error: Argument 1 to "append" of "list" has incompatible type "CtrFreq"; expected "PowerMeasurement" [arg-type] generated\nidaqmx\task.py:705: error: Argument 1 to "append" of "list" has incompatible type "CtrTime"; expected "PowerMeasurement" [arg-type] generated\nidaqmx\task.py:716: error: Argument 1 to "append" of "list" has incompatible type "CtrTick"; expected "PowerMeasurement" [arg-type] generated\nidaqmx\task.py:719: error: Incompatible types in assignment (expression has type "ndarray[Any, dtype[unsignedinteger[_32Bit]]]", variable has type "list[PowerMeasurement]") [assignment] generated\nidaqmx\task.py:726: error: Incompatible types in assignment (expression has type "ndarray[Any, dtype[floating[_64Bit]]]", variable has type "list[PowerMeasurement]") [assignment] generated\nidaqmx\task.py:753: error: "list[PowerMeasurement]" has no attribute "tolist" [attr-defined] generated\nidaqmx\task.py:757: error: No overload variant of "__getitem__" of "list" matches argument type "tuple[slice, slice]" [call-overload] generated\nidaqmx\task.py:757: note: Possible overload variants: generated\nidaqmx\task.py:757: note: def __getitem__(self, SupportsIndex, /) -> PowerMeasurement generated\nidaqmx\task.py:757: note: def __getitem__(self, slice, /) -> list[PowerMeasurement] generated\nidaqmx\task.py:759: error: "list[PowerMeasurement]" has no attribute "tolist" [attr-defined] generated\nidaqmx\task.py:761: error: "list[PowerMeasurement]" has no attribute "tolist" [attr-defined] generated\nidaqmx\task.py:1261: error: Incompatible types in assignment (expression has type "ndarray[Any, dtype[floating[_64Bit]]]", variable has type "list[Any]") [assignment] generated\nidaqmx\task.py:1262: error: Incompatible types in assignment (expression has type "ndarray[Any, dtype[floating[_64Bit]]]", variable has type "list[Any]") [assignment] generated\nidaqmx\task.py:1275: error: Incompatible types in assignment (expression has type "ndarray[Any, dtype[floating[_64Bit]]]", variable has type "list[Any]") [assignment] generated\nidaqmx\task.py:1276: error: Incompatible types in assignment (expression has type "ndarray[Any, dtype[floating[_64Bit]]]", variable has type "list[Any]") [assignment] generated\nidaqmx\task.py:1289: error: Incompatible types in assignment (expression has type "ndarray[Any, dtype[unsignedinteger[_32Bit]]]", variable has type "list[Any]") [assignment] generated\nidaqmx\task.py:1290: error: Incompatible types in assignment (expression has type "ndarray[Any, dtype[unsignedinteger[_32Bit]]]", variable has type "list[Any]") [assignment]
generated\nidaqmx\_lib.py:175: error: Argument 1 to "LoadLibrary" of "LibraryLoader" has incompatible type "Optional[str]"; expected "str" [arg-type]
generated\nidaqmx\_lib.py:10: error: Skipping analyzing "decouple": module is installed, but missing library stubs or py.typed marker [import-untyped] generated\nidaqmx\_lib.py:10: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
bkeryan
force-pushed
the
users/bkeryan/mcd-mypy
branch
from
March 4, 2024 22:54
5b11618
to
d54cceb
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What does this Pull Request accomplish?
Enable running mypy on the actual
nidaqmx
package without errors. For details, see commits.Update PR build workflow to run mypy on
generated/nidaqmx
.Why should this Pull Request be merged?
Even without type hints, running mypy on the
nidaqmx
package can catch bugs, such as passing the wrong arguments to a function.Running mypy on the
nidaqmx
package is a prerequisite for adding type hints.What testing has been done?
Ran
poetry run pytest -v
Ran
poetry run mypy generated/nidaqmx
andpoetry run mypy tests