pythonSoftIOC icon indicating copy to clipboard operation
pythonSoftIOC copied to clipboard

Provide stubs/annotations for RecordWrapper

Open AlexanderWells-diamond opened this issue 4 years ago • 1 comments

Currently there's no way for a user to know what EPICS record attributes are accessible on a RecordWrapper without just trying to get the attribute - and only a small handful are accessible at the moment. This would also help static type checkers such as mypy to better reason about the values retrieved from the record.

A basic introduction to stubs can be found here: https://mypy.readthedocs.io/en/stable/stubs.html

AlexanderWells-diamond avatar Oct 13 '21 08:10 AlexanderWells-diamond

To act as a starting point, here's a list of things I would like to have type hinting for. These are all in active use in my current project.

For RecordWrapper:

  • add_alias method - just the one string parameter (and documenting it requires the record prefix)
  • name attribute (I use this one a lot)
  • set , whose signature varies based on whether the record is In or Out, and based on the type of the record
  • set_alarm method, only available on In records.
  • get method, although the type this returns may be very difficult to work out

It may be useful to create InRecordWrapper and OutRecordWrapper types as well - these would help with typing to clearly show the different methods and signatures between the two. This would also serve as a fix to #52 , as all I really needed from that issue was to know whether it was an In or Out record so I knew which signature to use.

Under builder.records:

  • The bi/stringout etc. methods for creating records could have at least minimal hinting, the record name field, although documenting all possible EPICS keywords would be a chore.

AlexanderWells-diamond avatar Oct 13 '21 12:10 AlexanderWells-diamond