machinalis / mypy-data

mypy typesheds for the Python data stack
BSD 3-Clause "New" or "Revised" License
86 stars 23 forks source link

Stricter types for dtype arguments #4

Open dmoisset opened 8 years ago

dmoisset commented 8 years ago

Many functions accept a dtype argument for type conversions. That argument can be an instance of numpy.dtype or anything that can be converted to those by the numpy.dtype constructor. That includes:

More details available at http://docs.scipy.org/doc/numpy/reference/generated/numpy.dtype.html

Currently, those arguments are typed inconsistently as Any, object, or DtypeType which covers only the first case. The fix for this should probably cover:

  1. Giving all those arguments a DtypeSpec type
  2. change the numpy.dtype signature to accept a DtypeSpec argument
  3. Make DtypeSpec as close as possible to the description above.

For item 3, it's not necessary to cover everything that's possible but it should cover the most frequent uses.