pyro-ppl/pyro

Using Python type hints

Open

#2550 aperta il 6 lug 2020

Vedi su GitHub
 (7 commenti) (7 reazioni) (0 assegnatari)Python (981 fork)batch import
enhancementgood first issuetestingusabilitywarnings & errors

Metriche repository

Star
 (8211 star)
Metriche merge PR
 (Merge medio 10g 19h) (1 PR mergiata in 30 g)

Descrizione

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

Guida contributor