Make unary comparison ops evaluate their argument
This commit is contained in:
parent
9f0911161d
commit
7fcc7ac4b6
6
NEWS.rst
6
NEWS.rst
@ -3,6 +3,12 @@
|
||||
Unreleased
|
||||
==============================
|
||||
|
||||
Other Breaking Changes
|
||||
------------------------------
|
||||
* Non-shadow unary `=`, `is`, `<`, etc. now evaluate their argument
|
||||
instead of ignoring it. This change increases consistency a bit
|
||||
and makes accidental unary uses easier to notice.
|
||||
|
||||
Bug Fixes
|
||||
------------------------------
|
||||
* Fix `(return)` so it works correctly to exit a Python 2 generator
|
||||
|
@ -1574,7 +1574,8 @@ class HyASTCompiler(object):
|
||||
@checkargs(min=1)
|
||||
def compile_compare_op_expression(self, expression):
|
||||
if len(expression) == 2:
|
||||
return asty.Name(expression, id="True", ctx=ast.Load())
|
||||
return (self.compile(expression[1]) +
|
||||
asty.Name(expression, id="True", ctx=ast.Load()))
|
||||
return self._compile_compare_op_expression(expression)
|
||||
|
||||
@builds("!=", "is_not")
|
||||
|
@ -219,7 +219,15 @@
|
||||
|
||||
(op-and-shadow-test [= is]
|
||||
(forbid (f))
|
||||
|
||||
(assert (is (f "hello") True))
|
||||
|
||||
; Unary comparison operators, despite always returning True,
|
||||
; should evaluate their argument.
|
||||
(setv p "a")
|
||||
(assert (is (f (do (setv p "b") "hello")) True))
|
||||
(assert (= p "b"))
|
||||
|
||||
(defclass C)
|
||||
(setv x (get {"is" (C) "=" 0} f-name))
|
||||
(setv y (get {"is" (C) "=" 1} f-name))
|
||||
@ -229,6 +237,7 @@
|
||||
(assert (is (f y x) False))
|
||||
(assert (is (f x x x x x) True))
|
||||
(assert (is (f x x x y x) False))
|
||||
|
||||
(setv n None)
|
||||
(assert (is (f n None) True))
|
||||
(assert (is (f n "b") False)))
|
||||
|
Loading…
Reference in New Issue
Block a user