nebius/SWE-bench-extra huggingface dataset:
Repository: construct/construct

Issue:
Bitwise And is compiled as logical And
`ExprMixin` for bitwise has different behavior when compiled.

The following test is sufficient to catch the problem
```python
def test_compile_binexpr_bitwise_and():
    d = Struct(
        "a" / Int8ub,
        "cond" / If(this.a & 32, Int8ub),
        Terminated,
    )
    common(d, b"\x00", {"a": 0, "cond": None})
    common(d, b"\x01", {"a": 1, "cond": None})
    common(d, b" \x05", {"a": 32, "cond": 5})
```

Comments:

Patch:
diff --git a/construct/expr.py b/construct/expr.py
index 00a63f2..c1dd179 100644
--- a/construct/expr.py
+++ b/construct/expr.py
@@ -14,8 +14,8 @@ opnames = {
     operator.xor : "^",
     operator.lshift : "<<",
     operator.rshift : ">>",
-    operator.and_ : "and",
-    operator.or_ : "or",
+    operator.and_ : "&",
+    operator.or_ : "|",
     operator.not_ : "not",
     operator.neg : "-",
     operator.pos : "+",


Test patch:
diff --git a/tests/test_core.py b/tests/test_core.py
index 1876796..e92426c 100644
--- a/tests/test_core.py
+++ b/tests/test_core.py
@@ -2398,3 +2398,13 @@ def test_nullterminated_longterm_issue_1046():
     d = NullTerminated(GreedyBytes, term=b"END")
     assert d.parse(b"xxxEND") == b"xxx"
     raises(d.parse, b"xENDxx") == StreamError
+
+def test_compile_binexpr_bitwise_and_issue_1039():
+    d = Struct(
+        "a" / Int8ub,
+        "cond" / If(this.a & 32, Int8ub),
+        Terminated,
+    )
+    common(d, b"\x00", {"a": 0, "cond": None})
+    common(d, b"\x01", {"a": 1, "cond": None})
+    common(d, b" \x05", {"a": 32, "cond": 5})
Repository: construct/construct

Issue:
build_file() crashes when using RawCopy with a value only
Thank you for construct!

Here's a failing test case:

    def test_rawcopy_build_file_from_value_only(tmpdir):
        d = RawCopy(Byte)
        d.build_file(dict(value=0), filename=tmpdir.join('test'))

Version: master branch, commit 2626b39.

Expected result: success

Actual result:

    construct.core.StreamError: Error in path (building)
    stream.read() failed, requested 1 bytes

The cause is that `Construct.build_file()` opens the stream for writing only, but `RawCopy._build()` assumes that the stream is readable when it rewinds the stream to read out what was written to populate the `data` attribute.

Pull request to follow.

Comments:

Patch:
diff --git a/construct/core.py b/construct/core.py
index d2ec15e..785f4a0 100644
--- a/construct/core.py
+++ b/construct/core.py
@@ -351,7 +351,10 @@ class Construct(object):
         r"""
         Build an object into a closed binary file. See build().
         """
-        with open(filename, 'wb') as f:
+        # Open the file for reading as well as writing. This allows builders to
+        # read back the stream just written. For example. RawCopy does this.
+        # See issue #888.
+        with open(filename, 'w+b') as f:
             self.build_stream(obj, f, **contextkw)
 
     def _build(self, obj, stream, context, path):
diff --git a/construct/version.py b/construct/version.py
index b2c8dce..513a82f 100644
--- a/construct/version.py
+++ b/construct/version.py
@@ -1,3 +1,3 @@
-version = (2,10,56)
-version_string = "2.10.56"
-release_date = "2020.01.28"
+version = (2,10,57)
+version_string = "2.10.57"
+release_date = "2021.01.26"


Test patch:
diff --git a/tests/declarativeunittest.py b/tests/declarativeunittest.py
index d02a292..a39fb67 100644
--- a/tests/declarativeunittest.py
+++ b/tests/declarativeunittest.py
@@ -3,7 +3,7 @@ xfail = pytest.mark.xfail
 skip = pytest.mark.skip
 skipif = pytest.mark.skipif
 
-import os, math, random, collections, itertools, io, hashlib, binascii
+import os, math, random, collections, itertools, io, hashlib, binascii, tempfile
 
 from construct import *
 from construct.lib import *
diff --git a/tests/test_core.py b/tests/test_core.py
index 02e2e64..9da306c 100644
--- a/tests/test_core.py
+++ b/tests/test_core.py
@@ -930,6 +930,15 @@ def test_rawcopy_issue_358():
     d = Struct("a"/RawCopy(Byte), "check"/Check(this.a.value == 255))
     assert d.build(dict(a=dict(value=255))) == b"\xff"
 
+def test_rawcopy_issue_888():
+    # If you use build_file() on a RawCopy that has only a value defined, then
+    # RawCopy._build may also attempt to read from the file, which won't work
+    # if build_file opened the file for writing only.
+    with tempfile.TemporaryDirectory() as tmpdir:
+        fname = os.path.join(tmpdir, 'test')
+        d = RawCopy(Byte)
+        d.build_file(dict(value=0), filename=fname)
+
 def test_byteswapped():
     d = ByteSwapped(Bytes(5))
     common(d, b"12345", b"54321", 5)
Repository: cool-RR/PySnooper

Issue:
Problem with passing in a single tuple in custom_repr= ()
I was trying it on a toy example and just wanted to pass in one tuple like 
(list, print_list_size) to custom_repr= () with print_list_size being the example used in the readme file:
`
def print_list_size(l):
    return 'list(size={})'.format(len(l))
`

There was an exception:" TypeError: cannot unpack non-iterable function object." 
I think the problem lies in that custom_repr is a tuple of tuples thus when it has only one element it won't be unpacked successfully. 
I changed custom_repr = [ ] and then put in the tuple (list, print_list_size) and it worked. Or, put an extra , in the tuple such like this:
`
@pysnooper.snoop(custom_repr = ( (list, print_list_size), ))
`

Just a small issue but hopefully this would be beneficial for other people. 



Comments:

Patch:
diff --git a/pysnooper/tracer.py b/pysnooper/tracer.py
index 5d91aeb..fb6eddc 100644
--- a/pysnooper/tracer.py
+++ b/pysnooper/tracer.py
@@ -214,6 +214,9 @@ class Tracer:
         self.target_codes = set()
         self.target_frames = set()
         self.thread_local = threading.local()
+        if len(custom_repr) == 2 and not all(isinstance(x,
+                      pycompat.collections_abc.Iterable) for x in custom_repr):
+            custom_repr = (custom_repr,)
         self.custom_repr = custom_repr
 
     def __call__(self, function):


Test patch:
diff --git a/tests/test_pysnooper.py b/tests/test_pysnooper.py
index 0b93845..930dd5d 100644
--- a/tests/test_pysnooper.py
+++ b/tests/test_pysnooper.py
@@ -1174,6 +1174,30 @@ def test_custom_repr():
         )
     )
 
+def test_custom_repr_single():
+    string_io = io.StringIO()
+
+    @pysnooper.snoop(string_io, custom_repr=(list, lambda l: 'foofoo!'))
+    def sum_to_x(x):
+        l = list(range(x))
+        return 7
+
+    result = sum_to_x(10000)
+
+    output = string_io.getvalue()
+    assert_output(
+        output,
+        (
+            VariableEntry('x', '10000'),
+            CallEntry(),
+            LineEntry(),
+            VariableEntry('l', 'foofoo!'),
+            LineEntry(),
+            ReturnEntry(),
+            ReturnValueEntry('7'),
+        )
+    )
+
 
 def test_disable():
     string_io = io.StringIO()