DominicParent / pyproddi

A Python/Protocol Buffer based partial implementation of DDI.
Apache License 2.0
1 stars 0 forks source link

Type enforcement. #24

Open DominicParent opened 3 years ago

DominicParent commented 3 years ago

Use assertions for type enforcement.

assert isinstance(a, int), 'Expected int'

See https://www.youtube.com/watch?v=5nXmq1PsoJ0 @ 18:02.

DominicParent commented 3 years ago
class Contract:
    @classmethod
def check(cls, value):
    pass

class Integer(Contract):
    @classmethod
    def check(cls, value):
        assert isinstance(value, int), 'Expected int'