Skip to content

Bytes: add comparison operators (<, <=, >, >=) #559

@antonsynd

Description

@antonsynd

Summary

Python bytes supports lexicographic comparison (b"abc" < b"abd" is True). Currently only +, *, ==, !=, in are supported in the compiler. The <, <=, >, >= operators are missing from:

  1. OperatorValidator.cs — bytes dunder whitelist
  2. TypeInferenceService.TryInferBuiltinBinaryOp — bytes binary operator inference

Fix

  1. Add DunderNames.Lt or DunderNames.Le or DunderNames.Gt or DunderNames.Ge to the bytes case in OperatorValidator.cs
  2. Add cases returning SemanticType.Bool for those operators in TypeInferenceService.TryInferBuiltinBinaryOp

Found during architectural review of plan-1523bd.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions