def check_bidi(chars):
<EOL>if not chars:<EOL><INDENT>return<EOL><DEDENT>has_RandALCat = any(is_RandALCat(c) for c in chars)<EOL>if not has_RandALCat:<EOL><INDENT>return<EOL><DEDENT>has_LCat = any(is_LCat(c) for c in chars)<EOL>if has_LCat:<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>if not is_RandALCat(chars[<NUM_LIT:0>]) or not is_RandALCat(chars[-<NUM_LIT:1>]):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>
Check proper bidirectionality as per stringprep. Operates on a list of
unicode characters provided in `chars`.