quicktype icon indicating copy to clipboard operation
quicktype copied to clipboard

Please do not use assert() in python to enforce interface constraints.

Open bohndthi opened this issue 3 years ago • 0 comments

A typical generated python class looks like this:

@dataclass
class UpdateIssueEventNoteSchema:
    note: str

    @staticmethod
    def from_dict(obj: Any) -> 'UpdateIssueEventNoteSchema':
        assert isinstance(obj, dict)
        note = from_str(obj.get("note"))
        return UpdateIssueEventNoteSchema(note)

However, the assert and the enclosed code might will be removed when compiling to optimised byte code.

Please see https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html for more information.

I would suggest to throw an AssertionError explicitly.

bohndthi avatar Mar 17 '22 09:03 bohndthi