Skip to content

Better error for with block misuse #56

@jemcmahan13

Description

@jemcmahan13

With blocks should have the form

with ConditionalUpdate() as condition:
    with condition(...):
    ...
    with condition(...):
    ...
    etc.

Since the keywords and structure are intuitive, a common error may be to forget that each with statement takes a ConditionalUpdate object as argument (and not just a condition). E.g.,

with ConditionalUpdate() as condition:
    with (...):
    ...
    with (...):
    ...
    etc.

Right now this throws AttributeError: __exit__, which is not helpful if you don't know what you did wrong. If possible, a better error message would be useful.

Here's a complete example that throws the error message:

import sys
sys.path.append("..")
import pyrtl

a = pyrtl.WireVector(1)
b = pyrtl.WireVector(1)
c = pyrtl.WireVector(1)

with pyrtl.ConditionalUpdate() as condition:
    with condition(a & b):
        c |= 1
    with (a | b):
        c |= 0

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementProposed feature requests and improvements

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions