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

Issue:
[Gtk] WebView uses deprecated run_javascript api
### Describe the bug

The Gtk backend for `toga.WebView` uses the `run_javascript()` API to evaluate JavaScript. This was deprecated in WebView v2.40 in favour of `evaluate_javascript()`. Since we depend on WebKit v4.0 or later, we should switch to the non-deprecated API. See https://webkitgtk.org/reference/webkit2gtk/stable/method.WebView.run_javascript.html.

### Steps to reproduce

Evaluate some JavaScript using `toga.WebView` on Linux with the Gtk backend. See the followig deprecation warning:

```
/home/parallels/maestral/lib/python3.10/site-packages/toga_gtk/widgets/webview.py:106: DeprecationWarning: WebKit2.WebView.run_javascript is deprecated
  self.native.run_javascript(javascript, None, gtk_js_finished)
/home/parallels/maestral/lib/python3.10/site-packages/toga_gtk/widgets/webview.py:86: DeprecationWarning: WebKit2.WebView.run_javascript_finish is deprecated
  js_result = webview.run_javascript_finish(task)
```

### Expected behavior

Don't use deprecated APIs unless required for backward compatibility.

### Screenshots

_No response_

### Environment

- Operating System: Ubuntu 22.04
- Python version: Python 3.10
- Software versions:
  - Toga: 0.3.2.dev804+g609682318


### Logs

_No response_

### Additional context

_No response_


Discussion:

Resolving patch:
diff --git a/gtk/src/toga_gtk/widgets/webview.py b/gtk/src/toga_gtk/widgets/webview.py
--- a/gtk/src/toga_gtk/widgets/webview.py
+++ b/gtk/src/toga_gtk/widgets/webview.py
@@ -80,11 +80,10 @@ def evaluate_javascript(self, javascript, on_result=None):
         # Define a callback that will update the future when
         # the Javascript is complete.
         def gtk_js_finished(webview, task, *user_data):
-            """If `run_javascript_finish` from GTK returns a result, unmarshal it, and
+            """If `evaluate_javascript_finish` from GTK returns a result, unmarshal it, and
             call back with the result."""
             try:
-                js_result = webview.run_javascript_finish(task)
-                value = js_result.get_js_value()
+                value = webview.evaluate_javascript_finish(task)
                 if value.is_boolean():
                     value = value.to_boolean()
                 elif value.is_number():
@@ -103,7 +102,14 @@ def gtk_js_finished(webview, task, *user_data):
 
         # Invoke the javascript method, with a callback that will set
         # the future when a result is available.
-        self.native.run_javascript(javascript, None, gtk_js_finished)
+        self.native.evaluate_javascript(
+            script=javascript,
+            length=len(javascript),
+            world_name=None,
+            source_uri=None,
+            cancellable=None,
+            callback=gtk_js_finished,
+        )
 
         # wait for the future, and return the result
         return result


Test patch:
Repository: beeware/toga

Issue:
WeakrefCallable Class implementation is faulty
### Describe the bug

The WeakrefCallable class implemented in #2066 appears to be a faulty one. As such the items in the app menu do not work when clicked on. Moreover, the weakref.ref() calls added to the different places also appears to be problematic. The event handlers wrapped in weakref also do not fire.

### Steps to reproduce

1. Clone the latest main branch of the toga repository.
2. Install the cloned repo.
3. Create a default helloworld project in briefcase.
4. Run the project in dev mode.
5. Try to click on the menu items like "Exit".
6. The handlers attached to the menu items won't fire.


### Expected behavior

The app menu items like "Exit" should fire their attached handlers.

### Screenshots

_No response_

### Environment

- Operating System: Windows 11
- Python version: 3.10.6
- Software versions:
  - Briefcase: Latest
  - Toga: Latest from the main branch
  - ...


### Logs

```

```


### Additional context

_No response_


Discussion:

Resolving patch:
diff --git a/winforms/src/toga_winforms/app.py b/winforms/src/toga_winforms/app.py
--- a/winforms/src/toga_winforms/app.py
+++ b/winforms/src/toga_winforms/app.py
@@ -155,7 +155,7 @@ def create_menus(self):
                 item = WinForms.ToolStripMenuItem(cmd.text)
 
                 if cmd.action:
-                    item.Click += WeakrefCallable(cmd._impl.as_handler())
+                    item.Click += WeakrefCallable(cmd._impl.winforms_handler)
                 item.Enabled = cmd.enabled
 
                 if cmd.shortcut is not None:
diff --git a/winforms/src/toga_winforms/command.py b/winforms/src/toga_winforms/command.py
--- a/winforms/src/toga_winforms/command.py
+++ b/winforms/src/toga_winforms/command.py
@@ -8,8 +8,5 @@ def set_enabled(self, value):
             for widget in self.native:
                 widget.Enabled = self.interface.enabled
 
-    def as_handler(self):
-        def handler(sender, event):
-            return self.interface.action(None)
-
-        return handler
+    def winforms_handler(self, sender, event):
+        return self.interface.action(None)
diff --git a/winforms/src/toga_winforms/window.py b/winforms/src/toga_winforms/window.py
--- a/winforms/src/toga_winforms/window.py
+++ b/winforms/src/toga_winforms/window.py
@@ -61,7 +61,7 @@ def create_toolbar(self):
                         )
                     else:
                         item = WinForms.ToolStripMenuItem(cmd.text)
-                    item.Click += cmd._impl.as_handler()
+                    item.Click += WeakrefCallable(cmd._impl.winforms_handler)
                     cmd._impl.native.append(item)
                 self.toolbar_native.Items.Add(item)
 


Test patch:
Repository: beeware/toga

Issue:
Toga apps generate warning on macOS 14 (Sonoma)
### Describe the bug

Reported by Casimir1965 on Discord.

When running on macOS 14 (Sonoma), Toga apps generate a warning:
```
2023-11-02 11:10:34.900 Python[83553:21023244] WARNING: Secure coding is not enabled for restorable state! Enable secure coding by implementing NSApplicationDelegate.applicationSupportsSecureRestorableState: and returning YES.
```


### Steps to reproduce

At this point, somewhat unclear. As originally reported, it was "any Toga app"; however, based on [this feedback](https://github.com/beeware/toga/pull/2182#issuecomment-1791454601) it appears to not affect Toga apps running from the command line. 

Based on reading between the lines of the [AppKit release notes](https://developer.apple.com/documentation/macos-release-notes/appkit-release-notes-for-macos-14#Restorable-State), the problem may only affect apps deployed with Briefcase. 


### Expected behavior

No preventable warning is generated by a Toga app.

### Screenshots

_No response_

### Environment

- Operating System: macOS 14 (Sonoma)
- Python version: ?
- Software versions:
  - Briefcase: ?
  - Toga: ?


### Logs

```
2023-11-02 11:10:34.900 Python[83553:21023244] WARNING: Secure coding is not enabled for restorable state! Enable secure coding by implementing NSApplicationDelegate.applicationSupportsSecureRestorableState: and returning YES.
```


### Additional context

_No response_


Discussion:

Resolving patch:
diff --git a/cocoa/src/toga_cocoa/app.py b/cocoa/src/toga_cocoa/app.py
--- a/cocoa/src/toga_cocoa/app.py
+++ b/cocoa/src/toga_cocoa/app.py
@@ -60,6 +60,12 @@ class AppDelegate(NSObject):
     def applicationDidFinishLaunching_(self, notification):
         self.native.activateIgnoringOtherApps(True)
 
+    @objc_method
+    def applicationSupportsSecureRestorableState_(
+        self, app
+    ) -> bool:  # pragma: no cover
+        return True
+
     @objc_method
     def applicationOpenUntitledFile_(self, sender) -> bool:  # pragma: no cover
         self.impl.select_file()


Test patch:
Repository: beeware/toga

Issue:
On GTK, `App.current_window` returns the last active window even when all windows are hidden
### Describe the bug

On Cocoa and WinForms, it returns `None` in this situation, which I think makes more sense.

### Environment

- Software versions:
  - Toga: main (536a60f)


Discussion:

Resolving patch:
diff --git a/gtk/src/toga_gtk/app.py b/gtk/src/toga_gtk/app.py
--- a/gtk/src/toga_gtk/app.py
+++ b/gtk/src/toga_gtk/app.py
@@ -222,7 +222,8 @@ def exit(self):  # pragma: no cover
         self.native.quit()
 
     def get_current_window(self):
-        return self.native.get_active_window()._impl
+        current_window = self.native.get_active_window()._impl
+        return current_window if current_window.interface.visible else None
 
     def set_current_window(self, window):
         window._impl.native.present()


Test patch:
Repository: beeware/toga

Issue:
Winforms stack trace dialog buttons are unreliable
### Steps to reproduce

Open the `dialogs` example, and click "Stack Trace". The dialog appears, and then 1 second later, this appears in the console:
```
Task was destroyed but it is pending!
task: <Task pending name='Task-1' coro=<handler_with_cleanup() done, defined at C:\Users\smith\cygwin\git\beeware\toga\core\src\toga\handlers.py:36> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x000002612A605880>()]>>
```

Click the OK button. Nothing happens.

Click the close button. The dialog closes.

This only happens the first time you open the dialog in a process. In all subsequent dialogs, the OK button closes the dialog but the close button does not.

### Expected behavior

Based on the code, it looks like the intention is that the OK button closes the dialog but the close button does not.

### Environment

- Operating System: Windows 10
- Python version: 3.8
- Software versions:
  - Toga: 4a27e6e79b39aa3120ee255b2eec1da27bdf30be


Discussion:

Resolving patch:
diff --git a/winforms/src/toga_winforms/dialogs.py b/winforms/src/toga_winforms/dialogs.py
--- a/winforms/src/toga_winforms/dialogs.py
+++ b/winforms/src/toga_winforms/dialogs.py
@@ -165,7 +165,10 @@ def __init__(self, interface, title, message, content, retry):
 
             self.native.Controls.Add(accept)
 
-        self.start_inner_loop(self.native.ShowDialog)
+        def show():
+            self.native.ShowDialog()
+
+        self.start_inner_loop(show)
 
     def winforms_FormClosing(self, sender, event):
         # If the close button is pressed, there won't be a future yet.


Test patch:
Repository: beeware/toga

Issue:
run_in_executor not working on android
### Describe the bug

Refering to what reported [here](https://github.com/beeware/toga/issues/2099#issuecomment-1822354961) and [here](https://stackoverflow.com/a/77528365/15101154), the best approach to run a CPU-intensive task in backgroud is to use `run_in_executor`, that's works perfectly on Windows, but does not on Android.

### Steps to reproduce

A minimum (not)-working example to reproduce the error is the following:

```python
import toga, time

class MainApp(toga.App):
    def startup(self):

        self.main_window = toga.MainWindow(
            title=self.formal_name, size=(360, 654), resizable=True
        )
        self.label = toga.Label("")
        button = toga.Button("click here", on_press=self.click_handler)
        self.main_box = toga.Box(children=[button, self.label])
        self.main_window.content = self.main_box
        self.main_window.show()

        self.loop.create_task(self.loop_task())

    def click_handler(self, widget):
        self.label.text = "Clicked"

    async def loop_task(self):
        while True:
            await self.loop.run_in_executor(None, time.sleep, 1)
            self.label.text = time.time()


def main():
    return MainApp("Example App", "com.example")
```



### Expected behavior

If your run it on Windows (via `briefcase dev` or `briefcase run windows`) it does the job update the label every second, but if I run it on android `briefcase run android`, the application freezes after the first render and don't respond

### Screenshots

<img src="https://github.com/beeware/toga/assets/62117874/b78c5a9e-b09d-4804-8ddc-ed11f4d08ced" width=300/>


### Environment

- Operating System: Windows 11
- Python version: 3.11.5
- Software versions:
  - Briefcase: 0.3.17
  - Toga: 0.4.2



Discussion:

Resolving patch:
diff --git a/android/src/toga_android/libs/events.py b/android/src/toga_android/libs/events.py
--- a/android/src/toga_android/libs/events.py
+++ b/android/src/toga_android/libs/events.py
@@ -49,12 +49,6 @@ def __init__(self):
         # Create placeholders for lazily-created objects.
         self.android_interop = AndroidInterop()
 
-    # Override parent `run_in_executor()` to run all code synchronously. This disables the
-    # `executor` thread that typically exists in event loops. The event loop itself relies
-    # on `run_in_executor()` for DNS lookups. In the future, we can restore `run_in_executor()`.
-    async def run_in_executor(self, executor, func, *args):
-        return func(*args)  # pragma: no cover
-
     # Override parent `_call_soon()` to ensure Android wakes us up to do the delayed task.
     def _call_soon(self, callback, args, context):
         ret = super()._call_soon(callback, args, context)


Test patch:
Repository: beeware/toga

Issue:
Update Linux system requirements for WebKit2
### Describe the bug

The story for ensuring system requirements on Linux for WebKit2 are installed has been complicated by the release of 4.1.

Many of the distros are offering 4.0 and 4.1 while others (notably Ubuntu 24.04) only offer 4.1; see https://github.com/beeware/beeware/issues/333#issuecomment-2070550463.

### Steps to reproduce

See [documentation](https://github.com/beeware/toga/blob/main/docs/reference/platforms/unix-prerequisites.rst).

### Expected behavior

The [documentation](https://github.com/beeware/toga/blob/main/docs/reference/platforms/unix-prerequisites.rst) needs to be updated so users know how to install WebKit2.

I think as much as possible, we should push people towards 4.1.

Another complicating factor will likely be the introduction of GTK4...since I believe that's version 6.x of GTK's WebKit2. It hasn't been clear to me if the plan is to only support GTK4...or if a transition period will support both.

### Screenshots

_No response_

### Environment

- Operating System: ubuntu 24.04
- Toga: 0.4.2


### Logs

_No response_

### Additional context

_No response_


Discussion:

Resolving patch:
diff --git a/gtk/src/toga_gtk/libs/gtk.py b/gtk/src/toga_gtk/libs/gtk.py
--- a/gtk/src/toga_gtk/libs/gtk.py
+++ b/gtk/src/toga_gtk/libs/gtk.py
@@ -16,7 +16,7 @@
 try:
     try:
         gi.require_version("WebKit2", "4.1")
-    except ValueError:
+    except ValueError:  # pragma: no cover
         gi.require_version("WebKit2", "4.0")
     from gi.repository import WebKit2  # noqa: F401
 except (ImportError, ValueError):  # pragma: no cover
diff --git a/gtk/src/toga_gtk/widgets/mapview.py b/gtk/src/toga_gtk/widgets/mapview.py
--- a/gtk/src/toga_gtk/widgets/mapview.py
+++ b/gtk/src/toga_gtk/widgets/mapview.py
@@ -71,7 +71,9 @@ def create(self):
         if WebKit2 is None:  # pragma: no cover
             raise RuntimeError(
                 "Unable to import WebKit2. Ensure that the system package "
-                "providing Webkit2 and its GTK bindings have been installed."
+                "providing WebKit2 and its GTK bindings have been installed. "
+                "See https://toga.readthedocs.io/en/stable/reference/api/widgets/mapview.html#system-requirements "
+                "for details."
             )
 
         self.native = WebKit2.WebView()
diff --git a/gtk/src/toga_gtk/widgets/webview.py b/gtk/src/toga_gtk/widgets/webview.py
--- a/gtk/src/toga_gtk/widgets/webview.py
+++ b/gtk/src/toga_gtk/widgets/webview.py
@@ -13,7 +13,9 @@ def create(self):
         if WebKit2 is None:  # pragma: no cover
             raise RuntimeError(
                 "Unable to import WebKit2. Ensure that the system package "
-                "providing Webkit2 and its GTK bindings have been installed."
+                "providing WebKit2 and its GTK bindings have been installed. "
+                "See https://toga.readthedocs.io/en/stable/reference/api/widgets/webview.html#system-requirements "
+                "for details."
             )
 
         self.native = WebKit2.WebView()


Test patch:
Repository: sktime/sktime

Issue:
Documentation needs to be fixed 
Single comment line on `sktime.utils.validation.forecasting` needs to be fixed. Check the image below.

Instead of `<<<<<<< HEAD:sktime/utils/validation/forecasting.py` we should see `Returns`.
 
![image](https://user-images.githubusercontent.com/7353520/66719148-2c0d0580-edc2-11e9-9a10-8632c1d896e4.png)


Discussion:

Resolving patch:
diff --git a/sktime/utils/validation/forecasting.py b/sktime/utils/validation/forecasting.py
--- a/sktime/utils/validation/forecasting.py
+++ b/sktime/utils/validation/forecasting.py
@@ -14,7 +14,6 @@ def validate_y_X(y, X):
     y : pandas Series or numpy ndarray
     X : pandas DataFrame
 
-<<<<<<< HEAD:sktime/utils/validation/forecasting.py
     Returns
     -------
     None


Test patch:
Repository: sktime/sktime

Issue:
Conflict between the default and documentation value of TimeSeriesForestClassifier.
**Describe the bug**
At the documentation of TimeSeriesForestClassifier, `n_estimators = 100`.
https://github.com/alan-turing-institute/sktime/blob/4dabe1afee0ad180f31c5f585f904f515ab4d0b1/sktime/classifiers/compose/ensemble.py#L48

However, at the constructor, the default value is `n_estimators = 500`.
https://github.com/alan-turing-institute/sktime/blob/4dabe1afee0ad180f31c5f585f904f515ab4d0b1/sktime/classifiers/compose/ensemble.py#L185

**Expected behavior**
All of `n_estimators` should be either all 100 or 500.



Discussion:

Resolving patch:
diff --git a/sktime/classifiers/compose/ensemble.py b/sktime/classifiers/compose/ensemble.py
--- a/sktime/classifiers/compose/ensemble.py
+++ b/sktime/classifiers/compose/ensemble.py
@@ -45,7 +45,7 @@ class TimeSeriesForestClassifier(ForestClassifier):
     base_estimator : Pipeline
         A pipeline consisting of series-to-tabular transformers
         and a decision tree classifier as final estimator.
-    n_estimators : integer, optional (default=100)
+    n_estimators : integer, optional (default=200)
         The number of trees in the forest.
     criterion : string, optional (default="gini")
         The function to measure the quality of a split. Supported criteria are
@@ -75,7 +75,7 @@ class TimeSeriesForestClassifier(ForestClassifier):
         The minimum weighted fraction of the sum total of weights (of all
         the input samples) required to be at a leaf node. Samples have
         equal weight when sample_weight is not provided.
-    max_features : int, float, string or None, optional (default="auto")
+    max_features : int, float, string or None, optional (default=None)
         The number of features to consider when looking for the best split:
         - If int, then consider `max_features` features at each split.
         - If float, then `max_features` is a fraction and
@@ -103,10 +103,10 @@ class TimeSeriesForestClassifier(ForestClassifier):
         left child, and ``N_t_R`` is the number of samples in the right child.
         ``N``, ``N_t``, ``N_t_R`` and ``N_t_L`` all refer to the weighted sum,
         if ``sample_weight`` is passed.
-    min_impurity_split : float, (default=1e-7)
+    min_impurity_split : float or None, (default=None)
         Threshold for early stopping in tree growth. A node will split
         if its impurity is above the threshold, otherwise it is a leaf.
-    bootstrap : boolean, optional (default=True)
+    bootstrap : boolean, optional (default=False)
         Whether bootstrap samples are used when building trees.
     oob_score : bool (default=False)
         Whether to use out-of-bag samples to estimate
@@ -182,7 +182,7 @@ class labels (multi-output problem).
 
     def __init__(self,
                  base_estimator=None,
-                 n_estimators=500,
+                 n_estimators=200,
                  criterion='entropy',
                  max_depth=None,
                  min_samples_split=2,


Test patch:
Repository: sktime/sktime

Issue:
[DOC]add new software in Wiki
#### Describe the issue linked to the documentation
I cannot find the LoudML in the Related Software in wiki page.https://github.com/alan-turing-institute/sktime/wiki/related-software
<!--
Tell us about the confusion introduced in the documentation.
-->
Loud ML is an open source time series inference engine built on top of TensorFlow. It's useful to forecast data, detect outliers, and automate your process using future knowledge. here is link： https://github.com/regel/loudml
#### Suggest a potential alternative/fix
could you add it into the list?
<!--
Tell us how we could improve the documentation in this regard.
-->



Discussion:
Hi @bingblackbean, thanks, wasn't aware of LoudML! 

How about we move the list of related software from the wiki to the website? That should make it more visible and easier to edit by others (people could simply open a PR). 

Resolving patch:
diff --git a/docs/source/conf.py b/docs/source/conf.py
--- a/docs/source/conf.py
+++ b/docs/source/conf.py
@@ -27,9 +27,9 @@
     sys.path.insert(0, os.path.abspath("../.."))
 
 # -- Project information -----------------------------------------------------
-PROJECT = "sktime"
-COPYRIGHT = "2019 - 2020 (BSD-3-Clause License)"
-AUTHOR = "sktime developers"
+project = "sktime"
+copyright = "2019 - 2020 (BSD-3-Clause License)"
+author = "sktime developers"
 
 # The full version, including alpha/beta/rc tags
 CURRENT_VERSION = f"v{sktime.__version__}"
@@ -189,7 +189,7 @@ def find_source():
 
 # One entry per manual page. List of tuples
 # (source start file, name, description, authors, manual section).
-man_pages = [(master_doc, "sktime", "sktime Documentation", [AUTHOR], 1)]
+man_pages = [(master_doc, "sktime", "sktime Documentation", [author], 1)]
 
 # -- Options for Texinfo output ----------------------------------------------
 
@@ -201,7 +201,7 @@ def find_source():
         master_doc,
         "sktime",
         "sktime Documentation",
-        AUTHOR,
+        author,
         "sktime",
         "One line description of project.",
         "Miscellaneous",


Test patch:
Repository: sktime/sktime

Issue:
[DOC] SlidingWindowSplitter start_with_window default value not consistent
#### Describe the issue linked to the documentation

https://github.com/alan-turing-institute/sktime/blob/139b9291fb634cce367f714a6132212b0172e199/sktime/forecasting/model_selection/_split.py#L174

It looks like the default value of start_with_window=False, but documentation states that it is True. Not sure which one was intended.

https://github.com/alan-turing-institute/sktime/blob/139b9291fb634cce367f714a6132212b0172e199/sktime/forecasting/model_selection/_split.py#L183

#### Suggest a potential alternative/fix
Change either the documentation or the default argument to match the other one




Discussion:
Hi @ngupta23 - thanks for raising the issue! 

I'd appreciate a PR that changes the docs. 
Ok, no problem. What default would you like it to be: True or False?
I think it should be True (related to #518)
I'd say we keep the code and adjust the docs, so default should be `False`.

Resolving patch:
diff --git a/sktime/forecasting/model_selection/_split.py b/sktime/forecasting/model_selection/_split.py
--- a/sktime/forecasting/model_selection/_split.py
+++ b/sktime/forecasting/model_selection/_split.py
@@ -172,7 +172,7 @@ class SlidingWindowSplitter(BaseWindowSplitter):
     window_length : int
     step_length : int
     initial_window : int
-    start_with_window : bool, optional (default=True)
+    start_with_window : bool, optional (default=False)
 
     Examples
     --------


Test patch: