pyro-ppl/pyro

Using Python type hints

开放

#2,550 创建于 2020年7月6日

 (7 条评论) (7 个反应) (0 位负责人)Python (981 个派生)batch import
enhancementgood first issuetestingusabilitywarnings & errors

仓库指标

星标
 (8,211 个星标)
PR 合并指标
 (平均合并 10天 19小时) (30 天内合并 1 个 PR)

描述

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

贡献者指南