internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: kivy/kivy

Issue:
Animation recursion depth exceeded issue
When 4 or more animated context instructions are sequentially called and repeated, a recursion error is thrown. This is the case for Color, Rotate, and Scale. Transform and Position are untested.
The code below will produce the error.

``` python
import kivy
kivy.require('1.8.0') # replace with your current kivy version !

from kivy.app import App
from kivy.uix.scatterlayout import ScatterLayout
from kivy.graphics import Color
from kivy.animation import Animation
from kivy.graphics.instructions import InstructionGroup
from kivy.graphics import Rectangle

class MyApp(App):

    def build(self):

        element_layout = ScatterLayout()

        instruction_group_list = InstructionGroup()

        color_context_list = Color(1, 0, 0)
        instruction_group_list.add(color_context_list)
        instruction_group_list.add(Rectangle(pos=(300, 300), size=(100, 100)))
        element_layout.canvas.add(instruction_group_list)

        color_animation = Animation(r=1, g=1, b=0, a=1)
        color_animation += Animation(r=1, g=1, b=1, a=1)
        color_animation += Animation(r=0, g=1, b=1, a=1)
        color_animation += Animation(r=1, g=0, b=0, a=1)

        color_animation.start(color_context_list)
        color_animation.repeat = True

        return element_layout

if __name__ == '__main__':
    MyApp().run()
```



Discussion:
This seems to be an issue with the way nested `Sequence`s handle events. I wrote up a quick workaround here: https://gist.github.com/kived/81546fb9a540128bc9ba

It's a poor workaround that is designed to work for @DigiCoyote, and not really a fix for the issue. It prevents the `on_complete` event from being fired when `stop()` is called from within `start()`.


Resolving patch:
diff --git a/kivy/animation.py b/kivy/animation.py
--- a/kivy/animation.py
+++ b/kivy/animation.py
@@ -394,7 +394,6 @@ def __init__(self, anim1, anim2):
         self.anim2 = anim2
 
         self.anim1.bind(on_start=self.on_anim1_start,
-                        on_complete=self.on_anim1_complete,
                         on_progress=self.on_anim1_progress)
         self.anim2.bind(on_complete=self.on_anim2_complete,
                         on_progress=self.on_anim2_progress)
@@ -408,6 +407,7 @@ def start(self, widget):
         self._widgets[widget.uid] = True
         self._register()
         self.anim1.start(widget)
+        self.anim1.bind(on_complete=self.on_anim1_complete)
 
     def stop(self, widget):
         self.anim1.stop(widget)
@@ -433,6 +433,7 @@ def on_anim1_start(self, instance, widget):
         self.dispatch('on_start', widget)
 
     def on_anim1_complete(self, instance, widget):
+        self.anim1.unbind(on_complete=self.on_anim1_complete)
         self.anim2.start(widget)
 
     def on_anim1_progress(self, instance, widget, progress):
@@ -445,6 +446,7 @@ def on_anim2_complete(self, instance, widget):
         '''
         if self.repeat:
             self.anim1.start(widget)
+            self.anim1.bind(on_complete=self.on_anim1_complete)
         else:
             self.dispatch('on_complete', widget)
 


Test patch:
Repository: kivy/kivy

Issue:
Behavior of properties created in KV
The docs for "lang.py" says "[...] If the widget doesn’t have a property with the given name, an ObjectProperty will be automatically created and added to the instance.". This seems to be misleading -- for the example below, clearly it is not added only to the instance. I guess this is expected and should be fixed by clarifying the docs?

``` python
from kivy.lang import Builder
from kivy.factory import Factory

Builder.load_string('''
Widget:
    expected: 'no'
''')

x = Factory.Label()
print x.expected
```



Discussion:
A property is global yes. It's not something that only one instance can have, as properties are in the class definition.


Resolving patch:
diff --git a/kivy/lang.py b/kivy/lang.py
--- a/kivy/lang.py
+++ b/kivy/lang.py
@@ -107,7 +107,7 @@
 Here `prop1` and `prop2` are the properties of `ClassName` and `prop3` is the
 property of `AnotherClass`. If the widget doesn't have a property with
 the given name, an :class:`~kivy.properties.ObjectProperty` will be
-automatically created and added to the instance.
+automatically created and added to the widget.
 
 `AnotherClass` will be created and added as a child of the `ClassName`
 instance.


Test patch:
Repository: kivy/kivy

Issue:
Please distribute pxd files, expose c apis.
I'm writing some kivy extension code, and i want to cimport kivy's extension types, which is more efficient than python api, but kivy don't distribute pxd files to installation directory.
I can set PYTHONPATH to kivy's source directory, and ship cython compiled c file with my library, but it would be better if kivy distribute pxd files with it.



Discussion:

Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -727,6 +727,10 @@ def get_extensions_from_sources(sources):
         'kivy.uix', ],
     package_dir={'kivy': 'kivy'},
     package_data={'kivy': [
+        '*.pxd',
+        'core/text/*.pxd',
+        'graphics/*.pxd',
+        'lib/vidcore_lite/*.pxd',
         'data/*.kv',
         'data/*.json',
         'data/fonts/*.ttf',


Test patch:
Repository: kivy/kivy

Issue:
ListView adapter bug
When the data backing a ListView changes, the ListView does not always update correctly.

Sample code here:   https://gist.github.com/billmcc64/a97bd1db128c87a91026#file-listviewproblem-py

uncomment line 25 to correct the problem.

The ListView constructor executes the method bind_triggers_to_view() on the adapter.

If the adapter changes after the constructor has been called (as in this example, or if the ListView is created via a .kv file), this method does not get called, and updates to the data backing the ListView are not displayed.

Not sure the best way to fix this.   The **set** method in the ObjectProperty could be overriden for ListView to catch changes to the adapter.



Discussion:

Resolving patch:
diff --git a/kivy/uix/listview.py b/kivy/uix/listview.py
--- a/kivy/uix/listview.py
+++ b/kivy/uix/listview.py
@@ -899,12 +899,18 @@ def __init__(self, **kwargs):
                   item_strings=self.item_strings_changed,
                   adapter=self._trigger_populate)
 
+        self._trigger_bind_adapter = Clock.create_trigger(
+            lambda dt: self.adapter.bind_triggers_to_view(
+                self._trigger_reset_populate),
+            -1)
+        self.bind(adapter=self._trigger_bind_adapter)
+
         # The bindings setup above sets self._trigger_populate() to fire
         # when the adapter changes, but we also need this binding for when
         # adapter.data and other possible triggers change for view updating.
         # We don't know that these are, so we ask the adapter to set up the
         # bindings back to the view updating function here.
-        self.adapter.bind_triggers_to_view(self._trigger_reset_populate)
+        self._trigger_bind_adapter()
 
     # Added to set data when item_strings is set in a kv template, but it will
     # be good to have also if item_strings is reset generally.


Test patch:
Repository: kivy/kivy

Issue:
Please distribute pxd files, expose c apis.
I'm writing some kivy extension code, and i want to cimport kivy's extension types, which is more efficient than python api, but kivy don't distribute pxd files to installation directory.
I can set PYTHONPATH to kivy's source directory, and ship cython compiled c file with my library, but it would be better if kivy distribute pxd files with it.



Discussion:

Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -780,6 +780,14 @@ def get_extensions_from_sources(sources):
         'kivy.uix', ],
     package_dir={'kivy': 'kivy'},
     package_data={'kivy': [
+        '*.pxd',
+        '*.pxi',
+        'core/text/*.pxd',
+        'core/text/*.pxi',
+        'graphics/*.pxd',
+        'graphics/*.pxi',
+        'lib/vidcore_lite/*.pxd',
+        'lib/vidcore_lite/*.pxi',
         'data/*.kv',
         'data/*.json',
         'data/fonts/*.ttf',


Test patch:
Repository: kivy/kivy

Issue:
Kv "include" directive with reload is loading twice
By looking at the code in the `lang.py`:

``` python
                if ref in __KV_INCLUDES__:
                    if not force_load:
                        Logger.warn('WARNING: {0} has already been included!'
                                    .format(ref))
                        break
                    else:
                        Logger.debug('Reloading {0} because include was forced.'
                                    .format(ref))
                        Builder.unload_file(ref)
                        Builder.load_file(ref)
                if not os.path.isfile(ref):
                    raise ParserException(self, ln, 'Invalid or unknown file: '
                                                    '{0}'.format(ref))
                Logger.debug('Including file: {0}'.format(0))
                __KV_INCLUDES__.append(ref)
                Builder.load_file(ref)
```

If the file was already loaded, it will be unloaded once, but loaded twice after. I think that's an issue :)



Discussion:

Resolving patch:
diff --git a/kivy/lang.py b/kivy/lang.py
--- a/kivy/lang.py
+++ b/kivy/lang.py
@@ -1190,6 +1190,9 @@ def execute_directives(self):
                                 'Language extension (.kv)'.format(ref))
                     break
                 if ref in __KV_INCLUDES__:
+                    if not os.path.isfile(ref):
+                        raise ParserException(self, ln,
+                            'Invalid or unknown file: {0}'.format(ref))
                     if not force_load:
                         Logger.warn('WARNING: {0} has already been included!'
                                     .format(ref))
@@ -1199,9 +1202,7 @@ def execute_directives(self):
                                     .format(ref))
                         Builder.unload_file(ref)
                         Builder.load_file(ref)
-                if not os.path.isfile(ref):
-                    raise ParserException(self, ln, 'Invalid or unknown file: '
-                                                    '{0}'.format(ref))
+                        continue
                 Logger.debug('Including file: {0}'.format(0))
                 __KV_INCLUDES__.append(ref)
                 Builder.load_file(ref)


Test patch:
Repository: kivy/kivy

Issue:
Thou shalt always test both with Python 2 and Python 3
Introduced by: https://github.com/kivy/kivy/commit/1eabcff6b6ed2ea311470232148fdecdc2a3c31c

``` python
 Traceback (most recent call last):
   File "/home/vix/dev/prs/main/tests/test_11.py", line 1, in <module>
     from kivy.app import App
   File "/home/vix/dev/prs/kivy/kivy/app.py", line 316, in <module>
     from kivy.base import runTouchApp, stopTouchApp
   File "/home/vix/dev/prs/kivy/kivy/base.py", line 30, in <module>
     from kivy.lang import Builder
   File "/home/vix/dev/prs/kivy/kivy/lang.py", line 801, in <module>
     _cls_type = (type, types.ClassType)
 AttributeError: 'module' object has no attribute 'ClassType'
```



Discussion:

Resolving patch:
diff --git a/kivy/lang.py b/kivy/lang.py
--- a/kivy/lang.py
+++ b/kivy/lang.py
@@ -798,8 +798,10 @@ class MyWidget(Label):
 lang_tr = re.compile('(_\()')
 
 # class types to check with isinstance
-_cls_type = (type, types.ClassType)
-
+if PY2:
+    _cls_type = (type, types.ClassType)
+else:
+    _cls_type = (type, )
 
 # all the widget handlers, used to correctly unbind all the callbacks then the
 # widget is deleted


Test patch:
Repository: kivy/kivy

Issue:
setup.py - cython version check: ValueError: invalid literal for int() with base 10: '1post0'
Should be more failsave I think...

```
for PYX in python2.7 python3.4 ; do \
        /usr/bin/make build PYTHON=$PYX; \
    done
make[2]: Entering directory `/build/buildd/kivy-1.9.0-dev~testing0+201502071058-2609'
python2.7 setup.py build_ext --inplace
Traceback (most recent call last):
  File "setup.py", line 115, in <module>
    cy_version = tuple(map(int, cy_version_str.split('.')))
ValueError: invalid literal for int() with base 10: '1post0'
make[2]: *** [build] Error 1
make[2]: Leaving directory `/build/buildd/kivy-1.9.0-dev~testing0+201502071058-2609'
make[2]: Entering directory `/build/buildd/kivy-1.9.0-dev~testing0+201502071058-2609'
python3.4 setup.py build_ext --inplace
Traceback (most recent call last):
  File "setup.py", line 115, in <module>
    cy_version = tuple(map(int, cy_version_str.split('.')))
ValueError: invalid literal for int() with base 10: '1post0'
```
- https://launchpadlibrarian.net/196899423/buildlog_ubuntu-trusty-amd64.kivy_1.9.0-dev~testing0%2B201502071058-2609-testing65~ubuntu14.04.1_FAILEDTOBUILD.txt.gz



Discussion:

Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -3,11 +3,6 @@
 # http://kivy.org/
 #
 
-MIN_CYTHON_VERSION = (0, 20, 0)
-MIN_CYTHON_STRING = '.'.join(map(str, MIN_CYTHON_VERSION))
-MAX_CYTHON_VERSION = (0, 21, 1)
-MAX_CYTHON_STRING = '.'.join(map(str, MAX_CYTHON_VERSION))
-
 import sys
 
 from copy import deepcopy
@@ -16,8 +11,15 @@
 from os import walk, environ
 from distutils.core import setup
 from distutils.extension import Extension
+from distutils.version import LooseVersion
 from collections import OrderedDict
 
+
+MIN_CYTHON_STRING = '0.20.0'
+MIN_CYTHON_VERSION = LooseVersion(MIN_CYTHON_STRING)
+MAX_CYTHON_STRING = '0.21.1'
+MAX_CYTHON_VERSION = LooseVersion(MAX_CYTHON_STRING)
+
 if sys.version > '3':
     PY3 = True
 else:
@@ -112,13 +114,13 @@ def pkgconfig(*packages, **kw):
         have_cython = True
         import Cython
         cy_version_str = Cython.__version__
-        cy_version = tuple(map(int, cy_version_str.split('.')))
+        cy_ver = LooseVersion(cy_version_str)
         print('\nDetected Cython version {}'.format(cy_version_str))
-        if cy_version < MIN_CYTHON_VERSION:
+        if cy_ver < MIN_CYTHON_VERSION:
             print('  This version of Cython is not compatible with Kivy. ' +
                   'Please upgrade to at least {}'.format(MIN_CYTHON_STRING))
             raise ImportError('Incompatible Cython Version')
-        if cy_version > MAX_CYTHON_VERSION:
+        if cy_ver > MAX_CYTHON_VERSION:
             print('  This version of Cython is untested with Kivy. If you ' +
                   'experience issues, please downgrade to {}'
                   .format(MAX_CYTHON_STRING))


Test patch:
Repository: kivy/kivy

Issue:
SDL2: resizing re-add sdl input provider ?
If i resize a SDL2 window, here is the log:

```
[INFO   ] [Window      ] auto add sdl input provider
[INFO   ] [Window      ] auto add sdl input provider
[INFO   ] [Window      ] auto add sdl input provider
[INFO   ] [Window      ] auto add sdl input provider
[INFO   ] [Window      ] auto add sdl input provider
[INFO   ] [Window      ] auto add sdl input provider
[DEBUG  ] [Window      ] Resize window to [879, 647]
[INFO   ] [Window      ] auto add sdl input provider
[INFO   ] [Window      ] auto add sdl input provider
[INFO   ] [Window      ] auto add sdl input provider
[DEBUG  ] [Window      ] Resize window to [898, 662]
[INFO   ] [Window      ] auto add sdl input provider
[INFO   ] [Window      ] auto add sdl input provider
[INFO   ] [Window      ] auto add sdl input provider
[INFO   ] [Window      ] auto add sdl input provider
```

Something looks wrong :)



Discussion:

Resolving patch:
diff --git a/kivy/core/window/window_sdl2.py b/kivy/core/window/window_sdl2.py
--- a/kivy/core/window/window_sdl2.py
+++ b/kivy/core/window/window_sdl2.py
@@ -157,8 +157,11 @@ def create_window(self, *largs):
 
         super(WindowSDL, self).create_window()
 
+        if self.initialized:
+            return
+
         # auto add input provider
-        Logger.info('Window: auto add sdl input provider')
+        Logger.info('Window: auto add sdl2 input provider')
         from kivy.base import EventLoop
         SDL2MotionEventProvider.win = self
         EventLoop.add_input_provider(SDL2MotionEventProvider('sdl', ''))


Test patch:
Repository: kivy/kivy

Issue:
SDL2 window crash on (atleast) Windows
Run the following

``` python
from kivy.app import App
from kivy.uix.label import Label
class TestApp(App):
    def build(self):
        return Label(text='Use scroll wheel without having the mouse touch the kivy window first')
TestApp().run()
```

The new window gets focus, without touching the window with the mousepointer, scroll the scrollwheel. 
Result:

```
 Traceback (most recent call last):
   File "dbg.py", line 11, in <module>
     TestApp().run()
   File "C:\dev\python\kivy\kivy\kivy\app.py", line 824, in run
     runTouchApp()
   File "C:\dev\python\kivy\kivy\kivy\base.py", line 484, in runTouchApp
     EventLoop.window.mainloop()
   File "C:\dev\python\kivy\kivy\kivy\core\window\window_sdl2.py", line 478, in mainloop
     self._mainloop()
   File "C:\dev\python\kivy\kivy\kivy\core\window\window_sdl2.py", line 315, in _mainloop
     self._mouse_x, self._mouse_y, btn, self.modifiers)
 AttributeError: 'WindowSDL' object has no attribute '_mouse_x'
```

_mouse_x and _mouse_y aren't set, should probably just be set to 
self._mouse_x = x
self._mouse_y = y
as in the mousebutton\* or mousemotion cases.



Discussion:

Resolving patch:
diff --git a/kivy/core/window/window_sdl2.py b/kivy/core/window/window_sdl2.py
--- a/kivy/core/window/window_sdl2.py
+++ b/kivy/core/window/window_sdl2.py
@@ -99,6 +99,7 @@ class WindowSDL(WindowBase):
     def __init__(self, **kwargs):
         self._win = _WindowSDL2Storage()
         super(WindowSDL, self).__init__()
+        self._mouse_x = self._mouse_y = -1
         self._meta_keys = (KMOD_LCTRL, KMOD_RCTRL, KMOD_RSHIFT,
             KMOD_LSHIFT, KMOD_RALT, KMOD_LALT, KMOD_LMETA,
             KMOD_RMETA)


Test patch:
Repository: kivy/kivy

Issue:
Unable to get a Window, abort. kwargs not swallowed by EventDispatcher
[Crash Log](https://gist.github.com/FeralBytes/8145eb3db355e0860920)
Relevant Discussion:
(05:48:21 PM) kived: ah. yes, that's a bug
(05:48:48 PM) kived: recent change to the code which prevents kwargs from being swallowed by EventDispatcher, so they can be passed to another base class
(05:49:06 PM) kived: i worried that this might happen, but it didn't seem to in testing
(05:50:40 PM) kived: wolfrage: please submit an issue on github, reference PR #3037
(05:50:50 PM) wolfrage: kived: OK
(05:51:20 PM) matham: kived, but which param is responsible for that?
(05:51:53 PM) matham: I don't see the param that is not swallowed
(05:52:09 PM) matham: but anyway, that's a bug with the code, not pr, right?
(05:54:37 PM) kived: matham: dunno. but it's a change in behavior, previously it was ok to provide bogus kwargs
(05:55:15 PM) kived: just figure it should be discussed - and keeping it this way is a valid solution of course
(05:55:45 PM) matham: it's one of these args that is not accepted by it: https://github.com/kivy/kivy/blob/master/kivy/core/window/__init__.py#L572
(05:58:38 PM) matham: hmm all of the args added there are kivy props
(05:58:50 PM) matham: I wish we could see exactly what the kwargs is



Discussion:
This is likely because the `force` param is added to kwargs at https://github.com/kivy/kivy/blob/master/kivy/core/window/__init__.py#L524, but force is not a kivy property so EventDispatcher doesn't eat it.


Resolving patch:
diff --git a/kivy/core/window/__init__.py b/kivy/core/window/__init__.py
--- a/kivy/core/window/__init__.py
+++ b/kivy/core/window/__init__.py
@@ -521,11 +521,11 @@ def __new__(cls, **kwargs):
 
     def __init__(self, **kwargs):
 
-        kwargs.setdefault('force', False)
+        force = kwargs.pop('force', False)
 
         # don't init window 2 times,
         # except if force is specified
-        if WindowBase.__instance is not None and not kwargs.get('force'):
+        if WindowBase.__instance is not None and not force:
             return
 
         self.initialized = False


Test patch:
Repository: kivy/kivy

Issue:
Issues with popup on py3
When running the following code in py3 on windows I get the following error:

``` py
from kivy.uix.widget import Widget
from kivy.uix.popup import Popup

w1 = Widget()
w2 = Widget()
p1 = Popup(content=w1)
p2 = Popup(content=w2)
```

```
 Traceback (most recent call last):
   File "playground8.py", line 7, in <module>
     p2 = Popup(content=w2)
   File "C:\Users\Matthew Einhorn\Desktop\Kivy-1.8.0-py3.3-win32\kivy\kivy\uix\modalview.py", line 152, in __init__
     super(ModalView, self).__init__(**kwargs)
   File "C:\Users\Matthew Einhorn\Desktop\Kivy-1.8.0-py3.3-win32\kivy\kivy\uix\anchorlayout.py", line 68, in __init__
     super(AnchorLayout, self).__init__(**kwargs)
   File "C:\Users\Matthew Einhorn\Desktop\Kivy-1.8.0-py3.3-win32\kivy\kivy\uix\layout.py", line 66, in __init__
     super(Layout, self).__init__(**kwargs)
   File "C:\Users\Matthew Einhorn\Desktop\Kivy-1.8.0-py3.3-win32\kivy\kivy\uix\widget.py", line 261, in __init__
     super(Widget, self).__init__(**kwargs)
   File "kivy\_event.pyx", line 271, in kivy._event.EventDispatcher.__init__ (kivy\_event.c:4933)
   File "kivy\properties.pyx", line 397, in kivy.properties.Property.__set__ (kivy\properties.c:4680)
   File "kivy\properties.pyx", line 429, in kivy.properties.Property.set (kivy\properties.c:5203)
   File "kivy\properties.pyx", line 480, in kivy.properties.Property.dispatch (kivy\properties.c:5779)
   File "kivy\_event.pyx", line 1168, in kivy._event.EventObservers.dispatch (kivy\_event.c:12154)
   File "kivy\_event.pyx", line 1074, in kivy._event.EventObservers._dispatch (kivy\_event.c:11451)
   File "C:\Users\Matthew Einhorn\Desktop\Kivy-1.8.0-py3.3-win32\kivy\kivy\uix\popup.py", line 188, in on_content
     if not hasattr(value, 'popup'):
   File "kivy\properties.pyx", line 402, in kivy.properties.Property.__get__ (kivy\properties.c:4776)
   File "kivy\properties.pyx", line 435, in kivy.properties.Property.get (kivy\properties.c:5416)
 KeyError: 'popup'
```

The reason is because of https://github.com/kivy/kivy/blob/master/kivy/uix/popup.py#L188. Both Widgets are created first. Then upon creation of first Popup its `on_content` is executed and a property in that widget as well in Widget class is created. However, it's only initialized for w1, w2 `__storage` has not been initialized for w2. So when hasattr is called on widget 2 and in python 3 it causes obj.__storage['popup']` to be executed from get, because storage has not been initialized for 'popup' in this widget it crashes.

The question is, why does the Popup code do this `create_property` stuff?



Discussion:

Resolving patch:
diff --git a/kivy/uix/popup.py b/kivy/uix/popup.py
--- a/kivy/uix/popup.py
+++ b/kivy/uix/popup.py
@@ -185,9 +185,6 @@ def add_widget(self, widget):
             super(Popup, self).add_widget(widget)
 
     def on_content(self, instance, value):
-        if not hasattr(value, 'popup'):
-            value.create_property('popup')
-        value.popup = self
         if self._container:
             self._container.clear_widgets()
             self._container.add_widget(value)


Test patch: