nebius/SWE-bench-extra huggingface dataset:
Repository: acorg/dark-matter

Issue:
Extract-ORFs.py mistranslates lowercase letters
In a sequence with mixed uppercase and lowercase letters, extract-ORFs.py output has incorrect translations only for the sites of lowercase letters. (Even though the `translations` function of `dark/reads.py` translate a sequence with mixed upper and lower case letters correctly)

Comments:

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index fa389b6..e329501 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,10 @@
+## 3.0.60 Dec 13, 2018
+
+In `reads.py`, changed the `_makeComplementTable` function so that 
+uppercase and lowercase bases are correctly reverse complemented into their
+respective uppercase and lowercase complementary letters. Added a test to 
+`test/reads.py` to confirm that `reverseComplement` does this.
+
 ## 3.0.59 Dec 11, 2018
 
 Added `--sampleName` option to `proteins-to-pathogens`.
diff --git a/dark/__init__.py b/dark/__init__.py
index 278f52a..ffb465c 100644
--- a/dark/__init__.py
+++ b/dark/__init__.py
@@ -8,4 +8,4 @@ if sys.version_info < (2, 7):
 #
 # Remember to update ../CHANGELOG.md describing what's new in each version.
 
-__version__ = '3.0.59'
+__version__ = '3.0.60'
diff --git a/dark/reads.py b/dark/reads.py
index 18171d0..df381e0 100644
--- a/dark/reads.py
+++ b/dark/reads.py
@@ -27,7 +27,8 @@ def _makeComplementTable(complementData):
     """
     table = list(range(256))
     for _from, to in complementData.items():
-        table[ord(_from[0])] = ord(to[0])
+        table[ord(_from[0].lower())] = ord(to[0].lower())
+        table[ord(_from[0].upper())] = ord(to[0].upper())
     return ''.join(map(chr, table))
 
 


Test patch:
diff --git a/test/test_reads.py b/test/test_reads.py
index d586ab1..4663234 100644
--- a/test/test_reads.py
+++ b/test/test_reads.py
@@ -652,6 +652,16 @@ class TestDNARead(TestCase):
         read = DNARead('id', 'ATCGMRWSVHXN')
         self.assertEqual('NXDBSWYKCGAT', read.reverseComplement().sequence)
 
+    def testReverseComplementLowercaseLetters(self):
+        """
+        The reverseComplement function must correctly reverse complement
+        lowercase letters. The issue is described here:
+        https://github.com/acorg/dark-matter/issues/662
+        """
+        read = DNARead('id', 'CAGCAGctgcagcaccagcaccagcagcttcCACAT')
+        expected = ('ATGTGgaagctgctggtgctggtgctgcagCTGCTG')
+        self.assertEqual(expected, read.reverseComplement().sequence)
+
     def testTranslationsOfEmptySequence(self):
         """
         The translations function must correctly return all six (empty)
Repository: adamboche/python-marshmallow-union

Issue:
_serialize ignores the given value
The `_serialize` method of `Union` calls the `serialize` method (instead of `_serialize`) on the underlying fields. This means that it ignores the given `value` parameter, and may try to serialize a completely different value.

See: https://github.com/adamboche/python-marshmallow-union/blob/master/src/marshmallow_union/__init__.py#L66-L68

Initially reported in: https://github.com/lovasoa/marshmallow_dataclass/issues/67

Comments:

Patch:
diff --git a/src/marshmallow_union/__init__.py b/src/marshmallow_union/__init__.py
index 22d5ef4..ee47920 100644
--- a/src/marshmallow_union/__init__.py
+++ b/src/marshmallow_union/__init__.py
@@ -13,6 +13,7 @@ class MarshmallowUnionException(Exception):
 
 class ExceptionGroup(MarshmallowUnionException):
     """Collection of possibly multiple exceptions."""
+
     def __init__(self, msg: str, errors):
         self.msg = msg
         self.errors = errors
@@ -63,8 +64,8 @@ class Union(marshmallow.fields.Field):
         for candidate_field in fields:
 
             try:
-                return candidate_field.serialize(
-                    attr, obj, error_store=error_store, **kwargs
+                return candidate_field._serialize(
+                    value, attr, obj, error_store=error_store, **kwargs
                 )
             except ValueError as e:
                 error_store.store_error({attr: e})


Test patch:
diff --git a/tests/test_union.py b/tests/test_union.py
index 6377c06..c93f004 100644
--- a/tests/test_union.py
+++ b/tests/test_union.py
@@ -52,6 +52,14 @@ class IntStrSchema(marshmallow.Schema):
     x = marshmallow_union.Union([marshmallow.fields.Int(), marshmallow.fields.String()])
 
 
+class ListUnionSchema(marshmallow.Schema):
+    """Schema with a list of unions."""
+
+    l = marshmallow.fields.List(
+        marshmallow_union.Union([marshmallow.fields.Int(), marshmallow.fields.String()])
+    )
+
+
 @pytest.mark.parametrize(
     "data, schema",
     [
@@ -59,6 +67,7 @@ class IntStrSchema(marshmallow.Schema):
         ({"name": "Alice", "number_or_numbers": [25, 50]}, PersonSchema()),
         ({"name": "Alice", "number_or_numbers": [25, 50]}, OtherSchema()),
         ({"x": 5}, IntStrSchema()),
+        ({"l": ["h", 5, "n", 1]}, ListUnionSchema()),
         ({"x": "hello"}, IntStrSchema()),
         ({"items": {"a": 42, "b": [17]}}, MappingSchema()),
     ],
Repository: adamchainz/ec2-metadata

Issue:
availability_zone_id may return 404
### Python Version

3.8.10

### Package Version

2.7.0

### Description

In some cases `ec2_metadata.availability_zone_id` returns 404
```
----> 1 ec2_metadata.availability_zone_id
File functools.py:967, in __get__(self, instance, owner)
File ec2_metadata/__init__.py:87, in availability_zone_id(self)
File ec2_metadata/__init__.py:65, in _get_url(self, url, allow_404)
File requests/models.py:960, in raise_for_status(self)
HTTPError: 404 Client Error: Not Found for url: http://169.254.169.254/latest/meta-data/placement/availability-zone-id
```
I assume that all that is needed is to use `allow_404` in `_get_url`

Comments:

Patch:
diff --git a/HISTORY.rst b/HISTORY.rst
index 9a6d9e6..23dbfa2 100644
--- a/HISTORY.rst
+++ b/HISTORY.rst
@@ -2,6 +2,10 @@
 History
 =======
 
+* Return ``None`` for ``availability_zone_id`` when the underlying endpoint returns HTTP 404.
+
+  Thanks to Amir Rossert in `PR #350 <https://github.com/adamchainz/ec2-metadata/pull/350>`__.
+
 2.9.0 (2022-03-25)
 ------------------
 
diff --git a/README.rst b/README.rst
index 1671b48..f435b1f 100644
--- a/README.rst
+++ b/README.rst
@@ -133,8 +133,8 @@ See AWS docs page `Retrieve the target lifecycle state through instance metadata
 
 The name of the current AZ e.g. ``'eu-west-1a'``.
 
-``availability_zone_id: str``
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+``availability_zone_id: str | None``
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
 The unique, cross-account ID of the current AZ e.g. ``'use1-az6'``.
 See AWS docs page `AZ IDs for your AWS resources
diff --git a/src/ec2_metadata/__init__.py b/src/ec2_metadata/__init__.py
index 0db8376..520d9aa 100644
--- a/src/ec2_metadata/__init__.py
+++ b/src/ec2_metadata/__init__.py
@@ -98,8 +98,13 @@ class EC2Metadata(BaseLazyObject):
         return self._get_url(f"{self.metadata_url}placement/availability-zone").text
 
     @cached_property
-    def availability_zone_id(self) -> str:
-        return self._get_url(f"{self.metadata_url}placement/availability-zone-id").text
+    def availability_zone_id(self) -> str | None:
+        resp = self._get_url(
+            f"{self.metadata_url}placement/availability-zone-id", allow_404=True
+        )
+        if resp.status_code == 404:
+            return None
+        return resp.text
 
     @cached_property
     def ami_launch_index(self) -> int:


Test patch:
diff --git a/tests/test_ec2_metadata.py b/tests/test_ec2_metadata.py
index 24f6af1..55f701b 100644
--- a/tests/test_ec2_metadata.py
+++ b/tests/test_ec2_metadata.py
@@ -161,6 +161,14 @@ def test_availability_zone_id(em_requests_mock):
     assert ec2_metadata.availability_zone_id == "use1-az6"
 
 
+def test_availability_zone_id_none(em_requests_mock):
+    em_requests_mock.get(
+        "http://169.254.169.254/latest/meta-data/placement/availability-zone-id",
+        status_code=404,
+    )
+    assert ec2_metadata.availability_zone_id is None
+
+
 def test_domain(em_requests_mock):
     em_requests_mock.get(
         "http://169.254.169.254/latest/meta-data/services/domain",
Repository: adamchainz/pip-lock

Issue:
Crashes on lines providing arguments to pip
For example `--find-links`

Comments:

Patch:
diff --git a/HISTORY.rst b/HISTORY.rst
index ed86591..e15c981 100644
--- a/HISTORY.rst
+++ b/HISTORY.rst
@@ -2,6 +2,9 @@
 History
 =======
 
+* Fix to ignore lines that represent arguments to pip, such as
+  ``--find-links``.
+
 2.2.0 (2020-12-13)
 ------------------
 
diff --git a/src/pip_lock.py b/src/pip_lock.py
index 38edddf..a050b3f 100644
--- a/src/pip_lock.py
+++ b/src/pip_lock.py
@@ -27,7 +27,7 @@ def get_package_versions(lines, ignore_external_and_at=False):
     for line in lines:
         line = line.strip()
 
-        if len(line) == 0 or line.startswith("#") or line.startswith("-r "):
+        if len(line) == 0 or line.startswith(("#", "-")):
             continue
 
         if line.startswith("https://"):


Test patch:
diff --git a/tests/test_pip_lock.py b/tests/test_pip_lock.py
index cca27a5..7dde0c4 100644
--- a/tests/test_pip_lock.py
+++ b/tests/test_pip_lock.py
@@ -49,6 +49,9 @@ class TestGetPackageVersion:
     def test_ignore_includes(self):
         assert get_package_versions(["-r example.txt"]) == {}
 
+    def test_ignore_arguments(self):
+        assert get_package_versions(["--find-links file:./wheels"]) == {}
+
     def test_ignore_urls(self):
         assert get_package_versions(["https://www.google.com"]) == {}
Repository: adamchainz/time-machine

Issue:
[v2] ImportError for tzset on Windows
In one of my project, I received an automatic update to update time-machine to the newly published v2 and my CI crashes on Windows (Python 3.7, 3.8 and 3.9) with the following error:

```
ImportError: cannot import name 'tzset' from 'time' (unknown location)
```

I don't own a Windows machine, but one can check the logs here: https://github.com/browniebroke/netlify-builds/pull/27/checks?check_run_id=1716666697#step:6:52

Not really urgent or anything, but I thought I report the problem. Is it a missing dependency or something different with the stdlib?

Comments:

Patch:
diff --git a/HISTORY.rst b/HISTORY.rst
index 0178c5f..3548383 100644
--- a/HISTORY.rst
+++ b/HISTORY.rst
@@ -2,6 +2,8 @@
 History
 =======
 
+* Prevent ``ImportError`` on Windows where ``time.tzset()`` is unavailable.
+
 2.0.0 (2021-01-17)
 ------------------
 
diff --git a/src/time_machine.py b/src/time_machine.py
index ed2cfb2..9b4de81 100644
--- a/src/time_machine.py
+++ b/src/time_machine.py
@@ -5,7 +5,6 @@ import os
 import sys
 import uuid
 from time import gmtime as orig_gmtime
-from time import tzset
 from types import GeneratorType
 from typing import Optional
 from unittest import TestCase, mock
@@ -21,6 +20,12 @@ except ImportError:
     # Dummy value that won't compare equal to any value
     CLOCK_REALTIME = float("inf")
 
+try:
+    from time import tzset
+except ImportError:  # pragma: no cover
+    # Windows
+    tzset = None
+
 try:
     # Python 3.8+ or have installed backports.zoneinfo
     from zoneinfo import ZoneInfo
@@ -137,13 +142,13 @@ class Coordinates:
         self._start()
 
     def _start(self):
-        if self._destination_tzname is not None:
+        if tzset is not None and self._destination_tzname is not None:
             self._orig_tz = os.environ.get("TZ")
             os.environ["TZ"] = self._destination_tzname
             tzset()
 
     def _stop(self):
-        if self._destination_tzname is not None:
+        if tzset is not None and self._destination_tzname is not None:
             if self._orig_tz is None:
                 del os.environ["TZ"]
             else:


Test patch:
diff --git a/tests/test_time_machine.py b/tests/test_time_machine.py
index 8f6aa5f..ce7695b 100644
--- a/tests/test_time_machine.py
+++ b/tests/test_time_machine.py
@@ -379,6 +379,17 @@ def test_destination_datetime_tzinfo_zoneinfo_nested():
     assert time.tzname == orig_tzname
 
 
+@pytest.mark.skipif(ZoneInfo is None, reason="Requires ZoneInfo")
+def test_destination_datetime_tzinfo_zoneinfo_windows():
+    orig_timezone = time.timezone
+
+    pretend_windows_no_tzset = mock.patch.object(time_machine, "tzset", new=None)
+
+    dest = LIBRARY_EPOCH_DATETIME.replace(tzinfo=ZoneInfo("Africa/Addis_Ababa"))
+    with pretend_windows_no_tzset, time_machine.travel(dest):
+        assert time.timezone == orig_timezone
+
+
 @time_machine.travel(EPOCH_DATETIME.replace(tzinfo=None) + dt.timedelta(seconds=120))
 def test_destination_datetime_naive():
     assert time.time() == EPOCH + 120.0
Repository: adbar/simplemma

Issue:
in_target_language can count words twice and return ratios above 1.0
I noticed that in current `main` version, the `in_target_language` function can return ratios above 1.0 when given more than one language and the words in the input are matching several languages.

Example:

    >>> in_target_language('It was a true gift', lang='en')
    1.0
    >>> in_target_language('It was a true gift', lang='de')
    0.6666666666666666
    >>> in_target_language('It was a true gift', lang=('en','de'))
    1.6666666666666665

Simplemma 0.9.1 doesn't have this problem:

    >>> in_target_language('It was a true gift', lang='en')
    1.0
    >>> in_target_language('It was a true gift', lang='de')
    0.6666666666666666
    >>> in_target_language('It was a true gift', lang=('en','de'))
    1.0

It's not just a question of capping the scores at 1.0. The problem is that a single word can count more than once if it happens to match multiple languages. Below is an example that demonstrates the problem. I added nonsense words that don't match any language, but their presence is compensated by words that are counted twice.

Current `main` version:

    >>> in_target_language('It was a true gift xxx yyy', lang=('en','de'))
    1.0

Simplemma 0.9.1:

    >>> in_target_language('It was a true gift xxx yyy', lang=('en','de'))
    0.6

Comments:

Patch:
diff --git a/simplemma/language_detector.py b/simplemma/language_detector.py
index 52369a6..f6fab14 100644
--- a/simplemma/language_detector.py
+++ b/simplemma/language_detector.py
@@ -198,14 +198,18 @@ class LanguageDetector:
         Returns:
             float: The proportion of text in the target language(s).
         """
-        return sum(
-            percentage
-            for (
-                lang_code,
-                percentage,
-            ) in self.proportion_in_each_language(text).items()
-            if lang_code != "unk"
-        )
+        tokens = self._token_sampler.sample_text(text)
+        if len(tokens) == 0:
+            return 0
+
+        in_target = 0
+        for token in tokens:
+            for lang_code in self._lang:
+                candidate = self._lemmatization_strategy.get_lemma(token, lang_code)
+                if candidate is not None:
+                    in_target += 1
+                    break
+        return in_target / len(tokens)
 
     def main_language(
         self,


Test patch:
diff --git a/tests/test_language_detector.py b/tests/test_language_detector.py
index 4affdd1..ad68f0c 100644
--- a/tests/test_language_detector.py
+++ b/tests/test_language_detector.py
@@ -108,6 +108,15 @@ def test_in_target_language() -> None:
         == 1.0
     )
 
+    langs = ("en", "de")
+    text = "It was a true gift"
+    assert (
+        LanguageDetector(lang=langs).proportion_in_target_languages(text)
+        == in_target_language(text, lang=langs)
+        == 1.0
+    )
+    in_target_language("It was a true gift", lang=("en", "de"))
+
 
 def test_main_language():
     text = "Dieser Satz ist auf Deutsch."
Repository: aequitas/python-rflink

Issue:
decode_packet: too many values to unpack (expected 2)
I use rflink integration in my HA setup and often get this in HA log:

> 2020-01-22 07:49:56 ERROR (MainThread) [rflink.protocol] failed to parse packet: None
> Traceback (most recent call last):
>   File "/usr/local/lib/python3.7/site-packages/rflink/protocol.py", line 152, in handle_raw_packet
>     packet = decode_packet(raw_packet)
>   File "/usr/local/lib/python3.7/site-packages/rflink/parser.py", line 308, in decode_packet
>     key, value = attr.lower().split("=")
> ValueError: too many values to unpack (expected 2)

Obvoiusly there is no impact on the functionality, but the messages flood the log.
I hope it's possible to rewrite the code so it account for situations like this.

Comments:

Patch:
diff --git a/.travis.yml b/.travis.yml
index 30fa75f..e52730d 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -7,11 +7,13 @@ python:
 - 3.8
 - 2.7
 - pypy3
-install: pip install tox-travis python-coveralls codeclimate-test-reporter
+# python-coveralls 5.0 no longer supports python34
+install: pip install tox-travis codeclimate-test-reporter
 script: tox
 matrix:
   allow_failures:
   - python: 2.7
+  - python: 3.4
   - python: pypy3
   include:
     - python: 3.7
diff --git a/rflink/parser.py b/rflink/parser.py
index 05e7ea0..8a74a52 100644
--- a/rflink/parser.py
+++ b/rflink/parser.py
@@ -305,7 +305,7 @@ def decode_packet(packet: str) -> PacketType:
 
     # convert key=value pairs where needed
     for attr in filter(None, attrs.strip(DELIM).split(DELIM)):
-        key, value = attr.lower().split("=")
+        key, value = attr.lower().split("=", 1)
         if key in VALUE_TRANSLATION:
             value = VALUE_TRANSLATION[key](value)
         name = PACKET_FIELDS.get(key, key)
diff --git a/rflink/protocol.py b/rflink/protocol.py
index a3c54da..9922910 100644
--- a/rflink/protocol.py
+++ b/rflink/protocol.py
@@ -151,7 +151,7 @@ class PacketHandling(ProtocolBase):
         try:
             packet = decode_packet(raw_packet)
         except BaseException:
-            log.exception("failed to parse packet: %s", packet)
+            log.exception("failed to parse packet data: %s", raw_packet)
 
         log.debug("decoded packet: %s", packet)
 


Test patch:
diff --git a/tests/test_parse.py b/tests/test_parse.py
index 3f55831..274e0ae 100644
--- a/tests/test_parse.py
+++ b/tests/test_parse.py
@@ -80,6 +80,10 @@ PROTOCOL_SAMPLES = os.path.join(os.path.dirname(__file__), "protocol_samples.txt
             "20;00;Internal Pullup on RF-in disabled;",
             {"message": "Internal Pullup on RF-in disabled"},
         ],
+        [
+            "20;9A;FA500;ID=0000db9e;SWITCH=01;CMD=SET_LEVEL=2;",
+            {"command": "set_level=2"},
+        ],
     ],
 )
 def test_packet_parsing(packet, expect):
Repository: agronholm/anyio

Issue:
Handle partial asyncio future callbacks
As discussed on gitter,

```
    def find_root_task() -> asyncio.Task:
        try:
            root_task = _root_task.get()
        except LookupError:
            for task in all_tasks():
                if task._callbacks:
                    for cb in _get_task_callbacks(task):
>                       if cb is _run_until_complete_cb or cb.__module__ == 'uvloop.loop':
E                       AttributeError: 'functools.partial' object has no attribute '__module__'
```

Full trace: https://pastebin.com/hhqMvhpT, It happens roughly 10% of the time I run my tests.

Triggered by: https://github.com/vinissimus/async-asgi-testclient/blob/f3243ea332b0a91f3990676aa850fdf68676ae93/async_asgi_testclient/utils.py#L75

```python
def create_monitored_task(coro, send):
    future = asyncio.ensure_future(coro)
    future.add_done_callback(partial(_callback, send))
    return future
```

Anyio needs to handle the case where future callbacks are partial objects, and probably any kind of callable.

Comments:

Patch:
diff --git a/src/anyio/_backends/_asyncio.py b/src/anyio/_backends/_asyncio.py
index 02053e4..7a7eaaf 100644
--- a/src/anyio/_backends/_asyncio.py
+++ b/src/anyio/_backends/_asyncio.py
@@ -141,7 +141,8 @@ def find_root_task() -> asyncio.Task:
         for task in all_tasks():
             if task._callbacks:
                 for cb in _get_task_callbacks(task):
-                    if cb is _run_until_complete_cb or cb.__module__ == 'uvloop.loop':
+                    if (cb is _run_until_complete_cb
+                            or getattr(cb, '__module__', None) == 'uvloop.loop'):
                         _root_task.set(task)
                         return task
 


Test patch:
diff --git a/.github/workflows/codeqa-test.yml b/.github/workflows/codeqa-test.yml
index 21f0b69..5d7df2f 100644
--- a/.github/workflows/codeqa-test.yml
+++ b/.github/workflows/codeqa-test.yml
@@ -25,7 +25,7 @@ jobs:
     - name: Check types with Mypy
       run: mypy src
     - name: Run isort
-      run: isort -c src tests
+      run: isort -c --diff src tests
 
   test:
     needs: [lint]
diff --git a/tests/test_to_thread.py b/tests/test_to_thread.py
index e39c052..a0e43f1 100644
--- a/tests/test_to_thread.py
+++ b/tests/test_to_thread.py
@@ -2,6 +2,7 @@ import asyncio
 import sys
 import threading
 import time
+from functools import partial
 
 import pytest
 
@@ -148,3 +149,21 @@ def test_asyncio_no_root_task(asyncio_event_loop):
         if t.name == 'AnyIO worker thread':
             t.join(2)
             assert not t.is_alive()
+
+
+def test_asyncio_future_callback_partial(asyncio_event_loop):
+    """
+    Regression test for #272.
+
+    Ensures that futures with partial callbacks are handled correctly when the root task
+    cannot be determined.
+    """
+    def func(future):
+        pass
+
+    async def sleep_sync():
+        return await to_thread.run_sync(time.sleep, 0)
+
+    task = asyncio_event_loop.create_task(sleep_sync())
+    task.add_done_callback(partial(func))
+    asyncio_event_loop.run_until_complete(task)