vpn-slice icon indicating copy to clipboard operation
vpn-slice copied to clipboard

Add type hints and set up Mypy

Open gmacon opened this issue 5 years ago • 5 comments

OK, as I mentioned in https://github.com/dlenski/vpn-slice/issues/53#issuecomment-651131201, I've started thinking about setting up Mypy to try to catch some of these silly errors.

Here's what I've come up with so far:

  • Type hints were added in Python 3.5, but this project currently supports Python >=3.3. Would there be any objection to raising the minimum supported version to 3.5?
  • We should model the information read from the environment explicitly so that Mypy can know about it. It'd be handy to use Data Classes for that, which was added to Python in 3.7. We could still support Pythons 3.5 and 3.6 if we are prepared to add a dependency on Attrs for those old versions.
  • One of the things that makes Mypy hard to use in general is that lots of third-party packages don't have hints. I think we'll be OK on this front, since we don't have many third-party dependencies, and I noticed that dnspython does have hints when I was looking at it earlier.

gmacon avatar Jun 30 '20 15:06 gmacon

I think Debian Jessie ships Python 3.4 but support should end about now. I don't think distributions even further behind are going to package vpn-slice anytime soon so I guess dropping support for <3.5 won't cause much trouble.

mschilli87 avatar Jun 30 '20 15:06 mschilli87

@gmacon This sounds great. I have no issues with Python 3.5 as the minimum requirement. Ubuntu 16.04 comes with Python 3.5, and it's olllllllllld.

Doesn't seem like attrs-vs-data-classes will be too hard to combine, and it is indeed probably worth supporting Python 3.5-3.6.

dlenski avatar Jun 30 '20 17:06 dlenski

I've realized that using data classes or attrs-as-data-classes requires Python 3.6 to get the variable annotation syntax. To keep 3.5, we'll need to use attrs unconditionally.

gmacon avatar Jun 30 '20 18:06 gmacon

I got a tad bit carried away earlier, and I did some data modeling on the environment, wrote a parser, and wrote tests for it. I've pushed that up to a branch, but I can open a WIP PR with it if folks would prefer that mechanism for discussing. The question here is basically "do I have the right data model?"

gmacon avatar Jul 03 '20 01:07 gmacon

A mere 3 years later (:sweat_smile:), I started trying to do something similar in the typing_annotations branch.

dlenski avatar Jul 13 '23 23:07 dlenski