nebius/SWE-bench-extra huggingface dataset:
Repository: hsahovic/poke-env

Issue:
battle.fields
Hi Haris,

It seems to me like sometimes more than one terrain is returned by battle.fields
Could you please look into it


Comments:

Patch:
diff --git a/src/poke_env/environment/abstract_battle.py b/src/poke_env/environment/abstract_battle.py
index eb70606..ed07d0d 100644
--- a/src/poke_env/environment/abstract_battle.py
+++ b/src/poke_env/environment/abstract_battle.py
@@ -241,6 +241,14 @@ class AbstractBattle(ABC):
 
     def _field_start(self, field):
         field = Field.from_showdown_message(field)
+
+        if field.is_terrain:
+            self._fields = {
+                field: turn
+                for field, turn in self._fields.items()
+                if not field.is_terrain
+            }
+
         self._fields[field] = self.turn
 
     def _parse_message(self, split_message: List[str]) -> None:
diff --git a/src/poke_env/environment/field.py b/src/poke_env/environment/field.py
index 8822656..de213ff 100644
--- a/src/poke_env/environment/field.py
+++ b/src/poke_env/environment/field.py
@@ -54,3 +54,8 @@ class Field(Enum):
                 message,
             )
             return Field._UNKNOWN
+
+    @property
+    def is_terrain(self) -> bool:
+        """Wheter this field is a terrain."""
+        return self.name.endswith("_TERRAIN")


Test patch:
diff --git a/unit_tests/environment/test_battle.py b/unit_tests/environment/test_battle.py
index 4fc832b..2dbb7bc 100644
--- a/unit_tests/environment/test_battle.py
+++ b/unit_tests/environment/test_battle.py
@@ -524,3 +524,23 @@ def test_rules_are_tracked():
     battle._parse_message(["", "rule", "this is a rule!"])
 
     assert battle._rules == ["hello", "hi", "this is a rule!"]
+
+
+def test_field_terrain_interactions():
+    logger = MagicMock()
+    battle = Battle("tag", "username", logger)
+
+    battle._field_start("electricterrain")
+    assert battle.fields == {Field.ELECTRIC_TERRAIN: 0}
+    battle.turn = battle.turn + 1
+
+    battle._field_start("mistyterrain")
+    assert battle.fields == {Field.MISTY_TERRAIN: 1}
+    battle.turn = battle.turn + 1
+
+    battle._field_start("gravity")
+    assert battle.fields == {Field.MISTY_TERRAIN: 1, Field.GRAVITY: 2}
+    battle.turn = battle.turn + 1
+
+    battle._field_start("psychicterrain")
+    assert battle.fields == {Field.GRAVITY: 2, Field.PSYCHIC_TERRAIN: 3}
diff --git a/unit_tests/environment/test_enumerations.py b/unit_tests/environment/test_enumerations.py
index 6d20556..5e700b4 100644
--- a/unit_tests/environment/test_enumerations.py
+++ b/unit_tests/environment/test_enumerations.py
@@ -26,6 +26,18 @@ def test_field_str():
     assert str(Field["ELECTRIC_TERRAIN"])
 
 
+def test_field_is_terrain():
+    terrains = {
+        Field.ELECTRIC_TERRAIN,
+        Field.MISTY_TERRAIN,
+        Field.PSYCHIC_TERRAIN,
+        Field.GRASSY_TERRAIN,
+    }
+
+    for field in Field:
+        assert field.is_terrain == (field in terrains)
+
+
 def test_field_build():
     assert Field["ELECTRIC_TERRAIN"] == Field.from_showdown_message("electric terrain")
     assert Field["ELECTRIC_TERRAIN"] == Field.from_showdown_message(
Repository: html5lib/html5lib-python

Issue:
etree treewalker infinite loop
This goes into an infinite loop:

```python
import html5lib

frag = html5lib.parseFragment("<b><em><foo><foob><fooc><aside></b></em>")

walker = html5lib.getTreeWalker("etree")

print list(walker(frag))
```

Comments:

Patch:
diff --git a/html5lib/treebuilders/etree.py b/html5lib/treebuilders/etree.py
index d394148..4d12bd4 100644
--- a/html5lib/treebuilders/etree.py
+++ b/html5lib/treebuilders/etree.py
@@ -100,6 +100,7 @@ def getETreeBuilder(ElementTreeImplementation, fullTree=False):
             node.parent = self
 
         def removeChild(self, node):
+            self._childNodes.remove(node)
             self._element.remove(node._element)
             node.parent = None
 


Test patch:
diff --git a/html5lib/tests/test_parser2.py b/html5lib/tests/test_parser2.py
index 0ec5b04..b7a92fd 100644
--- a/html5lib/tests/test_parser2.py
+++ b/html5lib/tests/test_parser2.py
@@ -7,7 +7,7 @@ import io
 from . import support  # noqa
 
 from html5lib.constants import namespaces
-from html5lib import parse, HTMLParser
+from html5lib import parse, parseFragment, HTMLParser
 
 
 # tests that aren't autogenerated from text files
@@ -88,3 +88,8 @@ def test_debug_log():
             expected[i] = tuple(log)
 
     assert parser.log == expected
+
+
+def test_no_duplicate_clone():
+    frag = parseFragment("<b><em><foo><foob><fooc><aside></b></em>")
+    assert len(frag) == 2
Repository: hugovk/pypistats

Issue:
ValueError: month must be in 1..12
```console
$ pypistats python_minor pylast -m 2018-11
| category | percent | downloads |
|----------|--------:|----------:|
|      2.7 |  48.62% |     2,307 |
|      3.6 |  31.63% |     1,501 |
| null     |   7.31% |       347 |
|      3.7 |   6.91% |       328 |
|      3.5 |   4.85% |       230 |
|      3.4 |   0.59% |        28 |
|      3.3 |   0.08% |         4 |
| Total    |         |     4,745 |

$ pypistats python_minor pylast -m 2018-12
Traceback (most recent call last):
  File "/usr/local/bin/pypistats", line 11, in <module>
    load_entry_point('pypistats', 'console_scripts', 'pypistats')()
  File "/Users/hugo/github/pypistats/pypistats/cli.py", line 266, in main
    args.start_date, args.end_date = _month(args.month)
  File "/Users/hugo/github/pypistats/pypistats/cli.py", line 246, in _month
    last = date(year, month + 1, 1) - relativedelta(days=1)
ValueError: month must be in 1..12

$ pypistats python_minor pylast -m 2017-12
Traceback (most recent call last):
  File "/usr/local/bin/pypistats", line 11, in <module>
    load_entry_point('pypistats', 'console_scripts', 'pypistats')()
  File "/Users/hugo/github/pypistats/pypistats/cli.py", line 266, in main
    args.start_date, args.end_date = _month(args.month)
  File "/Users/hugo/github/pypistats/pypistats/cli.py", line 246, in _month
    last = date(year, month + 1, 1) - relativedelta(days=1)
ValueError: month must be in 1..12
```

Comments:

Patch:
diff --git a/pypistats/cli.py b/pypistats/cli.py
index 092f9b7..8eb62cd 100644
--- a/pypistats/cli.py
+++ b/pypistats/cli.py
@@ -243,7 +243,7 @@ def _month(yyyy_mm):
     """Helper to return start_date and end_date of a month as yyyy-mm-dd"""
     year, month = map(int, yyyy_mm.split("-"))
     first = date(year, month, 1)
-    last = date(year, month + 1, 1) - relativedelta(days=1)
+    last = first + relativedelta(months=1) - relativedelta(days=1)
     return str(first), str(last)
 
 


Test patch:
diff --git a/tests/test_cli.py b/tests/test_cli.py
index 22308f6..f486b7c 100644
--- a/tests/test_cli.py
+++ b/tests/test_cli.py
@@ -28,6 +28,17 @@ class TestCli(unittest.TestCase):
         self.assertEqual(first, "2018-07-01")
         self.assertEqual(last, "2018-07-31")
 
+    def test__month_12(self):
+        # Arrange
+        yyyy_mm = "2018-12"
+
+        # Act
+        first, last = cli._month(yyyy_mm)
+
+        # Assert
+        self.assertEqual(first, "2018-12-01")
+        self.assertEqual(last, "2018-12-31")
+
     @freeze_time("2018-09-25")
     def test__last_month(self):
         # Arrange
Repository: hylang/hy

Issue:
Misplaced tracebacks from some models created in the reader
```
$ echo ';;;;;;\na.b' >ex.hy
$ hy ex.hy 
Traceback (most recent call last):
  …
  File "/tmp/ex.hy", line 1, in <module>
    ;;;;;;
NameError: name 'a' is not defined
```

The error is wrongly attributed to line 1 because the reader fails to set position information for a model created during the expansion of `a.b` into `(. a b)`. Contrast with this case, which is correct:

```
$ echo ';;;;;;\n(. a b)' >ex.hy
$ hy ex.hy                     
Traceback (most recent call last):
  …
  File "/tmp/ex.hy", line 2, in <module>
    (. a b)
NameError: name 'a' is not defined
```

I believe it suffices to call `model.replace(model)` in `HyReader.fill_pos`, so that positions are fixed recursively. I just need to write a test.

This bug is more consequential than it sounds because it can crash pytest internally, when non-existent columns of the source are retrieved for a traceback. Hy's own error reporting doesn't fail so badly in such a case.

Comments:

Patch:
diff --git a/NEWS.rst b/NEWS.rst
index a0b30a20..6c8cb58f 100644
--- a/NEWS.rst
+++ b/NEWS.rst
@@ -7,7 +7,7 @@ Bug Fixes
 ------------------------------
 * Fixed an installation failure in some situations when version lookup
   fails.
-* Fixed traceback pointing in scripts with shebangs.
+* Fixed some bugs with traceback pointing.
 * Fixed some bugs with escaping in bracket f-strings
 
 New Features
diff --git a/hy/reader/hy_reader.py b/hy/reader/hy_reader.py
index 4483db6d..985baaa5 100644
--- a/hy/reader/hy_reader.py
+++ b/hy/reader/hy_reader.py
@@ -128,7 +128,9 @@ class HyReader(Reader):
         """
         model.start_line, model.start_column = start
         model.end_line, model.end_column = self.pos
-        return model
+        return model.replace(model)
+          # `replace` will recurse into submodels and set any model
+          # positions that are still unset the same way.
 
     def read_default(self, key):
         """Default reader handler when nothing in the table matches.


Test patch:
diff --git a/tests/test_reader.py b/tests/test_reader.py
index 89a7fc7a..3ef6e38c 100644
--- a/tests/test_reader.py
+++ b/tests/test_reader.py
@@ -410,6 +410,13 @@ def test_lex_line_counting_multi_inner():
     assert inner.start_column == 5
 
 
+def test_line_counting_dotted():
+    # https://github.com/hylang/hy/issues/2422
+    x, = tokenize(";;;;;\na.b")
+    for e in (x, *x):
+        assert e.start_line == 2
+
+
 def test_dicts():
     """Ensure that we can tokenize a dict."""
     objs = tokenize("{foo bar bar baz}")
Repository: hylang/hy

Issue:
`(hy.models.Symbol "#foo")` should be an error
for the same reason as `(hy.models.Symbol "5")`: `#foo` doesn't parse as a symbol. It parses as a reader-macro call.

Comments:

Patch:
diff --git a/NEWS.rst b/NEWS.rst
index cbd90377..d4765e98 100644
--- a/NEWS.rst
+++ b/NEWS.rst
@@ -29,6 +29,8 @@ Bug Fixes
 * The parser no longer looks for shebangs in the REPL or `hy -c`.
 * `require` with relative module names should now work correctly with
   `hy -m`, as well as `hy2py`'s recursive mode.
+* `hy.models.Symbol` no longer allows constructing a symbol beginning
+  with `#`.
 
 New Features
 ------------------------------
diff --git a/hy/reader/hy_reader.py b/hy/reader/hy_reader.py
index 016b94e5..923b820e 100644
--- a/hy/reader/hy_reader.py
+++ b/hy/reader/hy_reader.py
@@ -98,7 +98,7 @@ def as_identifier(ident, reader=None):
     if reader is None:
         if (
             not ident
-            or ident[:1] == ":"
+            or ident[0] in ":#"
             or any(isnormalizedspace(c) for c in ident)
             or HyReader.NON_IDENT.intersection(ident)
         ):


Test patch:
diff --git a/tests/macros/test_macro_processor.py b/tests/macros/test_macro_processor.py
index 5fb31791..464dcca8 100644
--- a/tests/macros/test_macro_processor.py
+++ b/tests/macros/test_macro_processor.py
@@ -55,7 +55,7 @@ def test_macroexpand_nan():
 
 def test_macroexpand_source_data():
     # https://github.com/hylang/hy/issues/1944
-    ast = Expression([Symbol("#@"), String("a")])
+    ast = Expression([Symbol("when"), String("a")])
     ast.start_line = 3
     ast.start_column = 5
     bad = macroexpand_1(ast, "hy.core.macros")
diff --git a/tests/test_models.py b/tests/test_models.py
index c000e8bd..9ad85154 100644
--- a/tests/test_models.py
+++ b/tests/test_models.py
@@ -28,7 +28,8 @@ def test_symbol_or_keyword():
     for x in ("foo", "foo-bar", "foo_bar", "✈é😂⁂"):
         assert str(Symbol(x)) == x
         assert Keyword(x).name == x
-    for x in ("", ":foo", "5"):
+    for x in ("", ":foo", "5", "#foo"):
+        # https://github.com/hylang/hy/issues/2383
         with pytest.raises(ValueError):
             Symbol(x)
         assert Keyword(x).name == x
Repository: hynek/argon2-cffi

Issue:
Make PasswordHasher.check_needs_rehash() accept bytes hash
`PasswordHasher.check_needs_rehash()` should also accept bytes hashes to be consistent with the rest of the API.

Comments:

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index e3fe7fb..46c0765 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -26,6 +26,12 @@ What explicitly *may* change over time are the default hashing parameters and th
 
 ## [Unreleased](https://github.com/hynek/argon2-cffi/compare/23.1.0...HEAD)
 
+### Changed
+
+- `argon2.PasswordHasher.check_needs_rehash()` now also accepts bytes like the rest of the API.
+  [#174](https://github.com/hynek/argon2-cffi/pull/174)
+
+
 ## [23.1.0](https://github.com/hynek/argon2-cffi/compare/21.3.0...23.1.0) - 2023-08-15
 
 ### Removed
diff --git a/src/argon2/_password_hasher.py b/src/argon2/_password_hasher.py
index 125149b..ef940b3 100644
--- a/src/argon2/_password_hasher.py
+++ b/src/argon2/_password_hasher.py
@@ -244,7 +244,7 @@ class PasswordHasher:
             hash, _ensure_bytes(password, self.encoding), hash_type
         )
 
-    def check_needs_rehash(self, hash: str) -> bool:
+    def check_needs_rehash(self, hash: str | bytes) -> bool:
         """
         Check whether *hash* was created using the instance's parameters.
 
@@ -264,5 +264,9 @@ class PasswordHasher:
             Whether *hash* was created using the instance's parameters.
 
         .. versionadded:: 18.2.0
+        .. versionchanged:: 24.1.0 Accepts bytes for *hash*.
         """
+        if isinstance(hash, bytes):
+            hash = hash.decode("ascii")
+
         return self._parameters != extract_parameters(hash)


Test patch:
diff --git a/tests/test_password_hasher.py b/tests/test_password_hasher.py
index d6fa626..17f9410 100644
--- a/tests/test_password_hasher.py
+++ b/tests/test_password_hasher.py
@@ -109,22 +109,32 @@ class TestPasswordHasher:
         with pytest.raises(InvalidHash):
             PasswordHasher().verify("tiger", "does not matter")
 
-    def test_check_needs_rehash_no(self):
+    @pytest.mark.parametrize("use_bytes", [True, False])
+    def test_check_needs_rehash_no(self, use_bytes):
         """
         Return False if the hash has the correct parameters.
         """
         ph = PasswordHasher(1, 8, 1, 16, 16)
 
-        assert not ph.check_needs_rehash(ph.hash("foo"))
+        hash = ph.hash("foo")
+        if use_bytes:
+            hash = hash.encode()
 
-    def test_check_needs_rehash_yes(self):
+        assert not ph.check_needs_rehash(hash)
+
+    @pytest.mark.parametrize("use_bytes", [True, False])
+    def test_check_needs_rehash_yes(self, use_bytes):
         """
         Return True if any of the parameters changes.
         """
         ph = PasswordHasher(1, 8, 1, 16, 16)
         ph_old = PasswordHasher(1, 8, 1, 8, 8)
 
-        assert ph.check_needs_rehash(ph_old.hash("foo"))
+        hash = ph_old.hash("foo")
+        if use_bytes:
+            hash = hash.encode()
+
+        assert ph.check_needs_rehash(hash)
 
     def test_type_is_configurable(self):
         """
Repository: hynek/structlog

Issue:
Interpolation raises an error for filtered out logs
Interpolation appears to be broken when the log is filtered out. Observed with structulog 22.2.0.

```python
import logging

import structlog

structlog.configure(
    processors=[
        structlog.contextvars.merge_contextvars,
        structlog.processors.add_log_level,
        structlog.processors.StackInfoRenderer(),
        structlog.dev.set_exc_info,
        structlog.processors.TimeStamper(),
        structlog.dev.ConsoleRenderer()
    ],
    # Note this is set at the INFO level
    wrapper_class=structlog.make_filtering_bound_logger(logging.INFO),
    context_class=dict,
    logger_factory=structlog.PrintLoggerFactory(),
    cache_logger_on_first_use=False
)
log = structlog.get_logger()

# Note this is at the DEBUG level, there's no problem at the INFO level or higher
log.debug('hello %s', 'world')
```

Traceback:
```
Traceback (most recent call last):
  File "/home/liquetm/dev/python-panels/bug.py", line 21, in <module>
    log.debug('hello %s', 'world')
TypeError: _nop() takes 2 positional arguments but 3 were given
```

Comments:

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8ddee6f..48eeb0c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -22,6 +22,12 @@ This prevents crashes if something different than a string is passed for the *ev
   [#475](https://github.com/hynek/structlog/pull/475)
 
 
+### Fixed
+
+- String interpolation doesn't cause crashes in filtered log call anymore.
+  [#478](https://github.com/hynek/structlog/pull/478)
+
+
 ## [22.2.0](https://github.com/hynek/structlog/compare/22.1.0...22.2.0) - 2022-11-19
 
 ### Deprecated
diff --git a/src/structlog/_log_levels.py b/src/structlog/_log_levels.py
index 4d49780..6e9fb1a 100644
--- a/src/structlog/_log_levels.py
+++ b/src/structlog/_log_levels.py
@@ -71,11 +71,11 @@ def add_log_level(
     return event_dict
 
 
-def _nop(self: Any, event: str, **kw: Any) -> Any:
+def _nop(self: Any, event: str, *args: Any, **kw: Any) -> Any:
     return None
 
 
-async def _anop(self: Any, event: str, **kw: Any) -> Any:
+async def _anop(self: Any, event: str, *args: Any, **kw: Any) -> Any:
     return None
 
 


Test patch:
diff --git a/tests/test_log_levels.py b/tests/test_log_levels.py
index fff9cce..2a0e579 100644
--- a/tests/test_log_levels.py
+++ b/tests/test_log_levels.py
@@ -61,6 +61,22 @@ class TestFilteringLogger:
 
         assert [] == cl.calls
 
+    def test_filtered_interp(self, bl, cl):
+        """
+        Passing interpolation args works if the log entry is filtered out.
+        """
+        bl.debug("hello %s!", "world")
+
+        assert [] == cl.calls
+
+    async def test_async_filtered_interp(self, bl, cl):
+        """
+        Passing interpolation args works if the log entry is filtered out.
+        """
+        await bl.adebug("hello %s!", "world")
+
+        assert [] == cl.calls
+
     def test_no_args(self, bl, cl):
         """
         If no args are passed, don't attempt intepolation.
Repository: iaroslavscript/elk-confd-parser

Issue:
hot fix for root.append AttributeError: 'dict' object has no attribute 'append'

Comments:

Patch:
diff --git a/elkconfdparser/__main__.py b/elkconfdparser/__main__.py
new file mode 100644
index 0000000..1615c0c
--- /dev/null
+++ b/elkconfdparser/__main__.py
@@ -0,0 +1,7 @@
+import sys
+
+from elkconfdparser.cli import main
+
+
+if __name__ == "__main__":  # noqa
+    main(sys.argv[1:])
diff --git a/elkconfdparser/cli.py b/elkconfdparser/cli.py
index d8d92a7..9e296b3 100644
--- a/elkconfdparser/cli.py
+++ b/elkconfdparser/cli.py
@@ -37,4 +37,4 @@ def display(data):
 
 
 if __name__ == "__main__":  # noqa
-    main(sys.argv[1:])
\ No newline at end of file
+    main(sys.argv[1:])
diff --git a/elkconfdparser/parser.py b/elkconfdparser/parser.py
index a4406fb..0fe7718 100644
--- a/elkconfdparser/parser.py
+++ b/elkconfdparser/parser.py
@@ -104,7 +104,7 @@ def _parse(text, start, end):  # noqa: C901  # FIXME
 
 def _drop_stack(root, stack):
     if len(stack) > 1:
-        root.append({stack.pop(): stack.pop()})
+        root.setdefault(stack.pop(), []).append(stack.pop())
 
         if len(stack):
             raise errors.StackNotEmptyException('Unknown operands left on stack after assigment')


Test patch:
diff --git a/tests/test_parser.py b/tests/test_parser.py
index 5a90c3a..8f1c6ea 100644
--- a/tests/test_parser.py
+++ b/tests/test_parser.py
@@ -3,6 +3,7 @@ import pytest
 from elkconfdparser import errors
 from elkconfdparser import parser
 
+
 class TestDropStack:
     @pytest.mark.parametrize(
         "input_root, input_stack, expected_root, expected_stack",
@@ -10,11 +11,11 @@ class TestDropStack:
             ({}, [], {}, []),
             ({}, [1], {}, [1]),
             ({}, [2, 1], {1: [2]}, []),
-            ({1:[8]}, [2, 1], {1: [8, 2]}, []),
-            ({1:[8], 3: [9]}, [2, 1], {1: [8, 2], 3: [9]}, []),
+            ({1: [8]}, [2, 1], {1: [8, 2]}, []),
+            ({1: [8], 3: [9]}, [2, 1], {1: [8, 2], 3: [9]}, []),
         ],
     )
-    def testTwoOperands(input_root, input_stack, expected_root, expected_stack):
+    def testTwoOperands(self, input_root, input_stack, expected_root, expected_stack):
 
         assert parser._drop_stack(input_root, input_stack) is None
         assert input_root == expected_root
@@ -23,10 +24,10 @@ class TestDropStack:
     @pytest.mark.parametrize(
         "input_root, input_stack, expected_root, expected_stack",
         [
-            ({}, [3, 2, 1,], {1: [2]}, [3]),
+            ({}, [3, 2, 1], {1: [2]}, [3]),
         ],
     )
-    def testMultipleOperands(input_root, input_stack, expected_root, expected_stack):
+    def testMultipleOperands(self, input_root, input_stack, expected_root, expected_stack):
 
         with pytest.raises(errors.StackNotEmptyException, match=r'.*operands left.*'):
             parser._drop_stack(input_root, input_stack)
Repository: icetemple/genrss

Issue:
Genrss don't return image
<!-- Describe the bug -->
When i add image or image_url, genrss generate xml without image.

### To Reproduce
Steps to reproduce the behavior:
1. Init GenRSS object with arguments title, site_url, feed_url and image_url with any link.
2. try to get xml.

```python
image_url = 'https://s3.smartfridge.me/image.jpg'
feed = GenRSS(
    title='SmartFridge',
    site_url='https://example.com/',
    feed_url='https://example.com/rss.xml',
    image_url='https://example.com/image.jpg'
)
xml = feed.xml()
```
### Expected Behavior
<!-- Tell us what should happen. -->
returns xml like
```python
'<image>'
       '<url>https://example.com/image.jpg</url>'
       '<link>https://example.com</link>'
       '<title><![CDATA[title]]></title>'
'</image>'
``` 

### Actual Behavior
<!-- Tell us what happens instead. -->
Returns xml without image attribute without errors.

### Environment

* OS: Ubuntu 20.04.1 LTS (64 bit)
* Python version: 3.8
* GenRSS version: 1.0.5


Comments:

Patch:
diff --git a/.gitignore b/.gitignore
index d9ecf51..361de9e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -152,4 +152,5 @@ tags
 
 # IDE
 .idea/
-.c9/
\ No newline at end of file
+.c9/
+.vscode/
\ No newline at end of file
diff --git a/genrss/__init__.py b/genrss/__init__.py
index 5dd3096..725cba3 100644
--- a/genrss/__init__.py
+++ b/genrss/__init__.py
@@ -100,7 +100,7 @@ class GenRSS:
         channel_image = self.image
         if not channel_image and self.image_url:
             channel_image = Image(self.image_url, self.site_url, self.title)
-        if isinstance(image, Image):
+        if isinstance(channel_image, Image):
             channel.append(channel_image.to_element())
 
         for category in self.categories:


Test patch:
diff --git a/tests/test_rss.py b/tests/test_rss.py
index d9c0eff..cbae47f 100644
--- a/tests/test_rss.py
+++ b/tests/test_rss.py
@@ -80,10 +80,15 @@ def test_feed_image_url():
     image_url = 'https://s3.smartfridge.me/image.jpg'
     feed = create_rss(image_url=image_url)
     xml = feed.xml()
+
     assert xml
-    assert (f'<image><url>{image_url}</url>'
+    assert (
+        '<image>'
+            f'<url>{image_url}</url>'
+            '<link>https://smartfridge.me/</link>'
             '<title><![CDATA[SmartFridge]]></title>'
-            '<link>https://smartfridge.me/</link></image>') in xml
+        '</image>'
+    ) in xml
 
 
 def test_feed_webmaster():