pyro-ppl/pyro

Using Python type hints

Open

#2550 opened on Jul 6, 2020

View on GitHub
 (7 comments) (7 reactions) (0 assignees)Python (8,211 stars) (981 forks)batch import
enhancementgood first issuetestingusabilitywarnings & errors

Description

Since Pyro supports exclusively Python 3, we should look into adding type hints. This has a few advantages:

  • pep8 linters can check for type errors
  • easier for a reader to understand function signatures. useful for eg funsor where multiple dispatching is prevalent.
  • sphinx docs can autogenerate types of args
  • IDE static analysis tools will work (better)

e.g.

from typing import List, Optional

def foo(bar: List, baz: Optional[List] = None) -> List:
    return bar

Add type hints to modules

  • contrib
  • distributions
  • distributions.transforms
  • distributions.constraints
  • infer
  • nn
    • #3337
    • #3342
  • ops
  • optim #2853
  • params #3271
  • poutine
    • #3321
    • #3312
    • #3309
    • #3308
    • #3306
    • #3299
    • #3295
    • #3292
    • #3290
    • #3288
  • scripts
  • tests.test_primitives
  • tests.test_generic (low priority)
  • tests.poutine
  • tests.ops
  • tests.optim
  • tests.perf
  • tests.nn
  • tests.infer
  • tests.distributions
  • tests.contrib

Additional functionality for type hints

  • Give warnings on #type ignore in codebase Grey might be a good idea for finding #type ignores
  • Give warnings on modules skipped by mypy

Contributor guide