Python type annotation of Galaxy and BioBlend: goals and progress
Nicola Soranzo
@NicolaSoranzo
European Galaxy Days 2022
Outline
www.earlham.ac.uk
Statically vs dynamically typed languages
www.earlham.ac.uk
Type checking
$ cat code.py
x = 4
print(f"x is {x}")
y = x + "hello"
$ python3 code.py
x is 4
Traceback (most recent call last):
File "code.py", line 3, in <module>
y = x + "hello"
TypeError: unsupported operand type(s) for +: 'int' and 'str'
www.earlham.ac.uk
Type annotations (or hints) in Python
def repeat(s: str, times: int) -> str:
return s * times
def repeat(s, times):
return s * times
www.earlham.ac.uk
Why add type annotations to Python code?
www.earlham.ac.uk
Available types
www.earlham.ac.uk
Other types
from typing import Sequence, TypeVar
T = TypeVar('T') # Declare type variable
def first(l: Sequence[T]) -> T: # Generic function
return l[0]
www.earlham.ac.uk
In-line annotations vs Stubs
class MyClass:
read_write: int
def do_stuff(self, y: str) -> bool: ...
www.earlham.ac.uk
Static type checking
www.earlham.ac.uk
Other resources
www.earlham.ac.uk
Type annotations in the Galaxy ecosystem
www.earlham.ac.uk
BioBlend annotation at GCC2022 Collaboration Fest
www.earlham.ac.uk
@NicolaSoranzo
Questions or comments?
Should we have an EGD CoFest type annotation project?
nicola.soranzo@earlham.ac.uk
Earlham Institute, Norwich Research Park, Norwich, Norfolk, NR4 7UZ, UK�www.earlham.ac.uk