santinic / pampy

Pampy: The Pattern Matching for Python you always dreamed of.
MIT License
3.52k stars 125 forks source link

raise in match #43

Closed sailfish009 closed 4 years ago

sailfish009 commented 4 years ago

Hi, below sample code give me error:

   return match
    (
        name,
        "WarmupMultiStepLR",  WarmupMultiStepLR( \
            optimizer, \
            cfg.SOLVER.STEPS, \
            cfg.SOLVER.GAMMA, \
            warmup_factor=cfg.SOLVER.WARMUP_FACTOR, \
            warmup_iters=cfg.SOLVER.WARMUP_ITERS, \
            warmup_method=cfg.SOLVER.WARMUP_METHOD, \
        ),
        "WarmupCosineLR", WarmupCosineLR( \
            optimizer, \
            cfg.SOLVER.MAX_ITER, \
            warmup_factor=cfg.SOLVER.WARMUP_FACTOR, \
            warmup_iters=cfg.SOLVER.WARMUP_ITERS, \
            warmup_method=cfg.SOLVER.WARMUP_METHOD, \
        ),
        _, raise ValueError("Unknown LR scheduler: {}".format(name))
    )

_, raise ValueError("Unknown LR scheduler: {}".format(name)) ^ SyntaxError: invalid syntax

rochacbruno commented 4 years ago

Maybe pampy needs a raise_error function to delegate error raising.

from pampy import match, _, raise_error

return match(x,
  1, "foo",
  2, "bar",
  _, raise_error(ValueError, "Message")
)