2

I have multiple numpy arrays with different objects. How can I give 'type-hint' to the Pycharm so that I can get methods of that class while coding? For example,

import numpy as np

class Test:
    def do_task():
       pass

data = [Test(), Test(), Test()]
my_array = np.array(data, dtype=Test)

def test_hint(array:np.ndarray):  # <-- I can give typehint as array but I also want to give hint about what kind of array it is.
    for a in array:
         a.... # Here I want Pycharm to give me list of methods from 'Test' class

I can always explicitly mention what kind of object it is like following,

for a in array:
   temp = a # type: Test
   temp... # Here Pycharm will give me all the suggestions.

Is there any way I can provide type-hint in the constructor so that I do not need to write additional line of code to declare type of data? I tried looking at python's type module for some clue, but couldn't find any.

Dexter
  • 1,421
  • 3
  • 22
  • 43
  • Why are you using array here? Iterating on `data` would be faster. It might not help with your hint problem, but I expect there's more discussion about doing this with lists than with arrays. – hpaulj Nov 15 '19 at 17:25
  • @hpaulj I have to use array because my program requires lot of reshaping of the data which is much easier with `numpy` array or `matrix` than regular iterators. – Dexter Nov 15 '19 at 18:01
  • Look here: https://stackoverflow.com/questions/59179493/numpy-typehint-with-nptyping-and-array-in-pycharm – NameVergessen Jan 14 '20 at 14:25

0 Answers0