A code reviewer flagged to me that I had written the code:
assert b'some html' in response.data in response.data
This is clearly incorrect but I missed this since it passed the test as expected.
Doing more testing in a Python 3.12 REPL, it seems the syntax x in y in z === x in y && y in z. However I couldn’t find any information on what this syntax is or what other operators have similar functionality. This seems to be something special and not operator precedence as both (x in y) in z and x in (y in z) lead to exceptions.
Does this kind of syntax have a name?
>Solution :
The syntax you’re referring to is called "chained comparison" or "chained operators." It’s a feature of Python that allows you to chain multiple comparison operators together in a single expression.
In Python, the expression x in y in z is equivalent to (x in y) and (y in z). This means that x is checked to be in y, and then y is checked to be in z, and the overall expression evaluates to True only if both conditions are True.
This syntax can make code more concise and readable in certain situations, but it’s essential to be cautious when using it to ensure clarity and avoid confusion, as you’ve experienced in your code review.
For More Clarification, have a look at this article: https://wiingy.com/learn/python/chaining-comparison-operators-in-python/