averagehat / pathos

0 stars 1 forks source link

Py3 + MyPy #4

Open averagehat opened 5 years ago

averagehat commented 5 years ago

Unfortunately this PR includes python3 changes as well as the mypy changes, I think up to a58386c

The version upgrade was necessitated for convenient mypy type annotations

A couple things:

  1. diff_ranks is going to be removed, as it is bugged and there is a correct implementation in summary.py
  2. MyPy has a generic(?) IO type. https://mypy.readthedocs.io/en/latest/cheat_sheet_py3.html#miscellaneous
  3. inline typing is supposed to look like x: int = 3
  4. mypy has a TypedDict, which is usual with argparse/docopt as well as the config file. However, we may be better of using pydantic or something similar (https://github.com/samuelcolvin/pydantic/pull/391) because we can hide the constructor behind assertions that enforce other guarantees about the type (like extant_file)
  5. Literals (only in latest version via dev/github): https://gist.github.com/averagehat/8aa433f85900559799c2896f19c985a7
averagehat commented 5 years ago

Maybe sh.py can be typed by typing the __getattr__ as returning a function which takes kwargs of values Union[int,str,Path]

It wold be good to use Path or an equivalent newtype exclusively (like in pipeline.py, but not the case in pathos_sheet.py). One consideration is that path.py does not work with pyfakefs which I will likely want to use for nice fast tests of the glue code. We may also want types like "OutPath" and "InPath." Along these lines, use of IO[Any] may be useful in avoiding a leak on pyfakefs tests (where because pyfakefs doesn't capture all filesystem operations, and something unintended happens on the real file system.