artofscience / SAOR

Sequential Approximate Optimization Repository
GNU General Public License v3.0
5 stars 1 forks source link

Should we use type annotations? #25

Closed aatmdelissen closed 3 years ago

aatmdelissen commented 3 years ago

Type annotations in Python define the type of relevant arguments and return variables. It helps IDE's with type hints (you can see which type is expected). For more info, see https://realpython.com/lessons/annotations/

def myfun(x: float, s: string):
    print(f"{s} =  {x}")
    return 3*x
MaxvdKolk commented 3 years ago

Haven't used it myself in Python yet, but I do think it helps the clarity of the code. Not sure if Sphinx can exploit this as well, but I assume those types will show up in the docs. That would make them quite helpful for others implementing their own classes etc.

I would be in favour of adding such annotations throughout the package

Giannis1993 commented 3 years ago

Agree! It will make the code more readable.

artofscience commented 3 years ago

Since we all agree, let's do this! Please pinpoint to others when documentation and/or annotations are incorrect :)

Giannis1993 commented 3 years ago

Since we all agreed on this issue, I think we can close it