tskit-dev / tskit

Population-scale genomics
MIT License
157 stars 74 forks source link

[Dev] Introduce type annotations? #472

Open jeromekelleher opened 4 years ago

jeromekelleher commented 4 years ago

@grahamgower brought up the idea of using type annotations in the code over in #471. I don't know much about it, so thought it would be good to have a discussion here of the pros and cons.

One abiding principle I think we should have though is that we should be conservative about Python versions. The approach taken so far (which we should document somewhere I guess) is that the minimum Python version tracks Debian stable.

benjeffery commented 4 years ago

Function annotation syntax has been a Python feature since version 3.0, but to use them properly you need 3.5 as that added the typing library and conventions. From what I can see tskit supports 3.6 and debian stable (buster) is on 3.7, so that shouldn't stop us. There's two main advantages:

It would be a lot of changes, but maybe worthwhile to do the later. I need to read through the code more to get an idea of cost/benefit.

jeromekelleher commented 4 years ago

Thanks @benjeffery, sounds good. OK, it sounds like one to think about in ~6 months once we've settled in to using the current bout of process improvements.

grahamgower commented 4 years ago

Let me caveat my comment by saying I haven't used type annotations in Python before, but.... My understanding is that type annotations can be added gradually. If its decided that type annotations are desirable, then there need not be a concerted effort to annote lots of existing code right now. But this shouldn't prevent the more adhoc introduction of a few type annotations in new code. A concerted effort can be made at any point in the future.

Possibly the benefit to tskit itself would be limited, but tskit-using code would get a benefit when doing static type checking.

benjeffery commented 4 years ago

Linking this here for later reference: https://www.bernat.tech/the-state-of-type-hints-in-python/