hdmf icon indicating copy to clipboard operation
hdmf copied to clipboard

Disallow or explicitly allow spec quantity to be specified with a numeric string

Open dsleiter opened this issue 4 years ago • 0 comments

The codebase seems to assume that a spec quantity is either a string from a reserved set of special characters or named wildcard quantities or an integer value. However, the spec schema documentation does not seem to exclude numeric strings and DatasetSpec accepts a numeric string quantity.

>>> from hdmf.spec import DatasetSpec
>>> ds = DatasetSpec('A Dataset', data_type_inc='Foo', quantity=1)
>>> ds.is_many()
False
>>> ds = DatasetSpec('A Dataset', data_type_inc='Foo', quantity='1')
>>> ds.is_many()
True

I'm not sure if this is a problem that's actually been encountered, but it seems likely to come up at some point.

Is your feature request related to a problem? Please describe. This came up while testing #526 and trying to determine what edge cases needed to be tested.

Describe the solution you'd like Options:

  • disallow numeric strings in the schema documentation and in BaseStorageSpec
  • explicitly allow it in the documentation and convert numeric strings to integer value in BaseStorageSpec.__init__

Describe alternatives you've considered Treat both integer and numeric strings in all cases where quantity is used.

Additional context None

Checklist

  • [x] Have you ensured the feature or change was not already reported ?
  • [x] Have you included a brief and descriptive title?
  • [x] Have you included a clear description of the problem you are trying to solve?
  • [x] Have you included a minimal code snippet that reproduces the issue you are encountering?
  • [x] Have you checked our Contributing document?

dsleiter avatar Mar 01 '21 03:03 dsleiter