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

Issue:
Bug: Component named 'self' in python is translated to 'this' in JS
Today we got a request for help troubleshooting an experiment that worked in PsychoPy but got stuck on the initialising screen in Pavlovia. The console log showed an invalid left-hand assignment error. It turned out they had named one of their components "self" (as in "self" image and "other" image), and the component name was translated to "this" in the JavaScript code, causing the error. I was able to duplicate the issue in a very basic experiment [here](https://gitlab.pavlovia.org/abbeyjoy/this_self/blob/master/this_self.js#L101). 

I looked around on the forums and issues but didn't see anything related to this, so apologies if it's a duplicate. At the very least it should maybe be mentioned in the documentation somewhere that "self" isn't currently a valid component name for experiments that will be run on Pavlovia.


Discussion:

Resolving patch:
diff --git a/psychopy/experiment/exports.py b/psychopy/experiment/exports.py
--- a/psychopy/experiment/exports.py
+++ b/psychopy/experiment/exports.py
@@ -136,7 +136,7 @@ def __init__(self, exp):
 
         self.numpy = _numpyImports + _numpyRandomImports + ['np']
         # noinspection PyUnresolvedReferences
-        self.keywords = keyword.kwlist + dir(__builtins__)
+        self.keywords = keyword.kwlist + dir(__builtins__) + ['self']
         # these are based on a partial test, known to be incomplete:
         self.psychopy = psychopy.__all__ + ['psychopy', 'os']
         self.constants = dir(constants)


Test patch:
Repository: psychopy/psychopy

Issue:
[Bug]: Error when clicking Save in Coder when no file open: AttributeError: ‘NoneType’ object has no attribute ‘filename’
### PsychoPy Version

2023.2.3

### What OS are your PsychoPy running on?

macOS Silicon

### Bug Description

Clicking Save in the Coder window when there is no file open will yield the following unhandled internal error:

```
Traceback (most recent call last):
  File “/Applications/PsychoPy.app/Contents/Resources/lib/python3.8/psychopy/app/coder/coder.py”, line 2405, in fileSave
AttributeError: ‘NoneType’ object has no attribute ‘filename’
```


### Expected Behaviour

Probably should just disable the Save button when no file is open.

### Steps to Reproduce

1. Open Coder
2. Ensure there is no file open
3. Click Save button
...


### Additional context

_No response_


Discussion:

Resolving patch:
diff --git a/psychopy/app/coder/coder.py b/psychopy/app/coder/coder.py
--- a/psychopy/app/coder/coder.py
+++ b/psychopy/app/coder/coder.py
@@ -2314,6 +2314,9 @@ def setCurrentDoc(self, filename, keepHidden=False):
         for key in ("runner", "pyrun", "pypilot"):
             if key in self.ribbon.buttons:
                 self.ribbon.buttons[key].Enable(isExp)
+        # update save/saveas buttons
+        self.ribbon.buttons['save'].Enable(readonly and self.currentDoc.UNSAVED)
+        self.ribbon.buttons['saveas'].Enable(bool(self.filename))
         # update menu items
         self.pavloviaMenu.syncBtn.Enable(bool(self.filename))
         self.pavloviaMenu.newBtn.Enable(bool(self.filename))
@@ -2538,8 +2541,11 @@ def fileClose(self, event, filename=None, checkSave=True):
             self.setTitle(title=self.winTitle, document=self.currentDoc)
             # clear the source tree
             self.structureWindow.srcTree.DeleteAllItems()
+            # disable save buttons
+            self.ribbon.buttons['save'].Disable()
+            self.ribbon.buttons['saveas'].Disable()
         else:
-            self.currentDoc = self.notebook.GetPage(newPageID)
+            self.setCurrentDoc(self.getOpenFilenames()[newPageID])
             self.structureWindow.refresh()
             # set to current file status
             self.setFileModified(self.currentDoc.UNSAVED)


Test patch:
Repository: psychopy/psychopy

Issue:
[Bug]: hardware.keyboard.waitKeys crash on Windows 11
### PsychoPy Version

2023.1.2

### What OS are your PsychoPy running on?

Windows 11

### Bug Description

On Win11, call the waitKeys method of a psychopy.hardware.keyboard.Keyboard instance.  If no key is pressed within ~6 seconds, Windows will flag python as unresponsive and terminate it.

In my experiment I replaced the stock waitKeys method with a monkey patched version.  Changing the time.sleep(0.00001) call to psychopy.core.wait(0.00001) fixed the problem.

### Expected Behaviour

The waitKeys call should wait politely until a key is pressed or maxWait is reached

### Steps to Reproduce

1.  hwkb = psychopy.hardware.keyboard.Keyboard()
2.  kwkb.waitKeys()
3.  Wait approx 6 seconds with no keyboard input, eventually Windows will produce the "Python is unresponsive" popup


### Additional context
Python 3.9.5

_No response_


Discussion:
Good catch @csarradet 
Digging a bit further, it looks like the issue is that the windows needs to keep processing events or Windows think it's died. 
`psychopy.clock.wait` includes a call to `psychopy.clock._dispatchWindowEvents` which `time.sleep` doesn't. I think adding that next to time.sleep in the waitKyes function would be a good way to go (rather than including core.wait which includes further unnecessary logic about whether we're hogging the CPU). Would you agree @mdcutone ?

@csarradet if you'd like to make that change/pull-request then you'll get the credit for tracking down the issue (we like contributors to get credit). If you'd prefer we do it that's fine too though
@peircej Thanks for the quick reply - you can go ahead with the fix

Resolving patch:
diff --git a/psychopy/hardware/keyboard.py b/psychopy/hardware/keyboard.py
--- a/psychopy/hardware/keyboard.py
+++ b/psychopy/hardware/keyboard.py
@@ -63,8 +63,6 @@
 import json
 from collections import deque
 import sys
-import copy
-import psychopy.core
 import psychopy.clock
 from psychopy import logging
 from psychopy.constants import NOT_STARTED
@@ -623,7 +621,7 @@ def waitKeys(self, maxWait=float('inf'), keyList=None, waitRelease=True,
         Returns None if times out.
     
         """
-        timer = psychopy.core.Clock()
+        timer = psychopy.clock.Clock()
 
         if clear:
             self.clearEvents()
@@ -632,6 +630,7 @@ def waitKeys(self, maxWait=float('inf'), keyList=None, waitRelease=True,
             keys = self.getKeys(keyList=keyList, waitRelease=waitRelease, clear=clear)
             if keys:
                 return keys
+            psychopy.clock._dispatchWindowEvents()  # prevent "app is not responding"
             time.sleep(0.00001)
 
         logging.data('No keypress (maxWait exceeded)')


Test patch:
Repository: psychopy/psychopy

Issue:
[Bug]: Selecting audio device in builder and coder. 
### PsychoPy Version

2023.2.3

### What OS are your PsychoPy running on?

Windows 10

### Bug Description

As described in this forum [post](https://discourse.psychopy.org/t/how-to-change-audiodevice-in-hardware-preferences/30982), switching audio device in builder preferences just reverts back to the default after hitting apply. 

I've tried to work around this by adding a code component to manually set the audio device as suggested by another user in that thread, but I then see the issue shown in this [thread](https://discourse.psychopy.org/t/error-with-psychportaudio-although-it-works-in-psychtoolbox/27764). I've tried both the ptb and pyo libraries. 

### Expected Behaviour

Sound device should change in preferences and be used in the experiment. 

### Steps to Reproduce

1. Install low latency sound card linked below with driver. 
2. Open psychopy builder and add a sound component. Specifying 250 (pure tone) as the Sound.
3. Open preferences > Hardware > audio device drop down > select your audio device (in my case Speakers (Lynx E44)
4. Run experiment. 



### Additional context

I'm using a low latency sound card, [Lynx e44](https://www.lynxstudio.com/downloads/e44/windows-driver-v2-build-26/) as my applications require audio output at frequencies not possible with the default windows card. This comes with its own driver that I've downloaded and added the .sys file name from the drivers folder (without the .sys extension), I'm not sure if this is correct. 

I'm able to produce sound from the sound card outside of psychopy, so the driver is properly installed. 


Discussion:
For now, using the sounddevice backend and psychopy version 2022.2.5 bypasses this problem, but I'd love to be able to use the ptb package in the future! 
We believe this is fixed in 2024.1.0 but let us know if it's still a problem in your set up

Resolving patch:
diff --git a/psychopy/app/preferencesDlg.py b/psychopy/app/preferencesDlg.py
--- a/psychopy/app/preferencesDlg.py
+++ b/psychopy/app/preferencesDlg.py
@@ -588,7 +588,7 @@ def populatePrefs(self):
                         options = self.audioDevNames
                         try:
                             default = self.audioDevNames.index(
-                                self.audioDevDefault)
+                                self.audioDevDefault[0])
                         except ValueError:
                             default = 0
                     else:
@@ -663,8 +663,8 @@ def applyPrefs(self):
                     self.app.theme = self.prefsCfg[sectionName][prefName] = self.themeList[thisPref]
                     continue
                 elif prefName == 'audioDevice':
-                    self.prefsCfg[sectionName][prefName] = \
-                        self.audioDevNames[thisPref]
+                    self.audioDevDefault = [self.audioDevNames[thisPref]]
+                    self.prefsCfg[sectionName][prefName] = self.audioDevDefault
                     continue
                 elif prefName == 'locale':
                     # '' corresponds to system locale


Test patch:
Repository: psychopy/psychopy

Issue:
[Bug]: Use of pythonw on macos conda/mamba environments breaks app
### PsychoPy Version

2024.1.3

### What OS are your PsychoPy running on?

macOS Silicon

### Bug Description

When attempting to run the psychopy GUI app following an install in a fresh conda environment:

```
conda create -n pyschopy python=3.10
pip install pyschopy
psychopy
```
Psychopy fails to start.


### Expected Behaviour

Psychopy should not need to call pythonw for versions of python >= 3.9, and the if statement in `psychopyApp.py` should be modified to reflect that probably (or python < 3.9 support dropped entirely for newer versions of the package).

### Steps to Reproduce

After installing as above the following error is returned:

```
Traceback (most recent call last):
  File "/Users/MYUSERNAME/mambaforge/envs/intermod/bin/psychopy", line 8, in <module>
    sys.exit(main())
  File "/Users/MYUSERNAME/mambaforge/envs/intermod/lib/python3.10/site-packages/psychopy/app/psychopyApp.py", line 90, in main
    stdout, stderr = core.shellCall(cmd,
  File "/Users/MYUSERNAME/mambaforge/envs/intermod/lib/python3.10/site-packages/psychopy/core.py", line 153, in shellCall
    proc = subprocess.Popen(cmdObjects, stdin=subprocess.PIPE,
  File "/Users/MYUSERNAME/mambaforge/envs/intermod/lib/python3.10/subprocess.py", line 971, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/Users/MYUSERNAME/mambaforge/envs/intermod/lib/python3.10/subprocess.py", line 1863, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: '/Users/MYUSERNAME/mambaforge/envs/intermod/bin/python3.10w'
```

This error happens because, according to `psychopyApp.py`, we need to call `pythonw` when running GUI scripts on MacOS in an Anaconda-based environment. However this is an outdated method as of Python 3.9, and [from that version onwards you can now directly call the python binary regardless](https://docs.python.org/3/using/mac.html#running-scripts-with-a-gui). 

In a fresh Python 3.10 installation via conda/mamba the pythonw binary does not exist in the binaries folder for the environment. I have for the moment fixed this by simply symlinking the base python binary to `python3.10w` which psychopy expects, which then allows the app to start.


### Additional context

_No response_


Discussion:

Resolving patch:
diff --git a/psychopy/app/psychopyApp.py b/psychopy/app/psychopyApp.py
--- a/psychopy/app/psychopyApp.py
+++ b/psychopy/app/psychopyApp.py
@@ -69,9 +69,8 @@ def main():
 """)
         sys.exit()
 
-    if (sys.platform == 'darwin' and
-            ('| packaged by conda-forge |' in sys.version or
-             '|Anaconda' in sys.version)):
+    if (('| packaged by conda-forge |' in sys.version or '|Anaconda' in sys.version)
+        and sys.platform == 'darwin' and sys.version_info >= (3,9)):
 
         # On macOS with Anaconda, GUI applications need to be run using
         # `pythonw`. Since we have no way to determine whether this is currently


Test patch:
Repository: nautobot/nautobot

Issue:
Replace `User` model with a custom model
After some discussions around the timing behind whether we should replace the `User` model, we decided it would be a good idea.

This gives us the opportunity go move the user model to have a UUID as primary key, and to prepare for future use-cases not supported by the default Django user model.


Discussion:

Resolving patch:
diff --git a/nautobot/core/__init__.py b/nautobot/core/__init__.py
--- a/nautobot/core/__init__.py
+++ b/nautobot/core/__init__.py
@@ -0,0 +1 @@
+from . import checks
diff --git a/nautobot/core/checks.py b/nautobot/core/checks.py
new file mode 100644
--- /dev/null
+++ b/nautobot/core/checks.py
@@ -0,0 +1,15 @@
+from django.conf import settings
+from django.core.checks import Error, Tags, register
+
+
+E001 = Error(
+    "CACHEOPS_DEFAULTS['timeout'] value cannot be 0. To disable caching set CACHEOPS_ENABLED=False.",
+    id="nautobot.E001",
+)
+
+
+@register(Tags.caches)
+def cache_timeout_check(app_configs, **kwargs):
+    if settings.CACHEOPS_DEFAULTS.get("timeout") == 0:
+        return [E001]
+    return []
diff --git a/nautobot/core/settings.py b/nautobot/core/settings.py
--- a/nautobot/core/settings.py
+++ b/nautobot/core/settings.py
@@ -459,6 +459,7 @@
     "virtualization.*": {"ops": "all"},
 }
 CACHEOPS_DEGRADE_ON_FAILURE = True
+CACHEOPS_ENABLED = True
 CACHEOPS_REDIS = "redis://localhost:6379/1"
 CACHEOPS_DEFAULTS = {"timeout": 900}
 


Test patch:
diff --git a/nautobot/core/tests/test_checks.py b/nautobot/core/tests/test_checks.py
new file mode 100644
--- /dev/null
+++ b/nautobot/core/tests/test_checks.py
@@ -0,0 +1,13 @@
+from django.test import TestCase
+from django.test import override_settings
+
+from nautobot.core import checks
+
+
+class CheckCacheopsDefaultsTest(TestCase):
+    @override_settings(
+        CACHEOPS_DEFAULTS={"timeout": 0},
+    )
+    def test_timeout_invalid(self):
+        """Error if CACHEOPS_DEFAULTS['timeout'] is 0."""
+        self.assertEqual(checks.cache_timeout_check(None), [checks.E001])
Repository: nautobot/nautobot

Issue:
Replace Gunicorn w/ uWSGI
<!--
    NOTE: This template is for use by maintainers only. Please do not submit
    an issue using this template unless you have been specifically asked to
    do so.
-->
### Proposed Changes

Self-explanatory

<!-- Provide justification for the proposed change(s). -->
### Justification

uWSGI is better for the common case and more stable. Our recommendation is to use uWSGi over Gunicorn in production, so we want to revise the requirements and the documentation to support this.


Discussion:
Note that `pyproject.toml` currently lists `gunicorn` as a hard dependency, so we'd want to remove that as well.
Yes, thanks. We should decide as to whether we want to include uWSGI as a hard dependency (I would argue not) or whether to include it as another extras (`pip3 install nautobot[wsgi]` or something).
This is one area where I like supporting optional dependencies. There are many different patterns to install, doesn't make sense to force that on the users. 

Resolving patch:
diff --git a/nautobot/core/management/commands/start.py b/nautobot/core/management/commands/start.py
new file mode 100644
--- /dev/null
+++ b/nautobot/core/management/commands/start.py
@@ -0,0 +1,5 @@
+from django_webserver.management.commands.pyuwsgi import Command as uWSGICommand
+
+
+class Command(uWSGICommand):
+    help = "Start Nautobot uWSGI server."


Test patch:
Repository: nautobot/nautobot

Issue:
Editing an existing user token shows "create" buttons instead of "update"
<!--
    NOTE: IF YOUR ISSUE DOES NOT FOLLOW THIS TEMPLATE, IT WILL BE CLOSED.

    This form is only for reporting reproducible bugs. If you need assistance
    with Nautobot installation, or if you have a general question, please start a
    discussion instead: https://github.com/nautobot/nautobot/discussions

    Please describe the environment in which you are running Nautobot. Be sure
    that you are running an unmodified instance of the latest stable release
    before submitting a bug report, and that any plugins have been disabled.
-->
### Environment
* Python version:
* Nautobot version:

<!--
    Describe in detail the exact steps that someone else can take to reproduce
    this bug using the current stable release of Nautobot. Begin with the
    creation of any necessary database objects and call out every operation
    being performed explicitly. If reporting a bug in the REST API, be sure to
    reconstruct the raw HTTP request(s) being made: Don't rely on a client
    library such as pynautobot.
-->
### Steps to Reproduce
1. Navigate to user "Profile"
2. Navigate to "API Tokens"
3. Click "Add token"
4. Click "Create"
5. From the token list view, click "Edit" on the token you just created

<!-- What did you expect to happen? -->
### Expected Behavior

There should be an "Update" button.

<!-- What happened instead? -->
### Observed Behavior

There are "Create" and "Create and Add Another" buttons. 

![Cursor_and_Notification_Center](https://user-images.githubusercontent.com/138052/111223484-7176c900-859a-11eb-95c0-289b9361b01a.png)




Discussion:

Resolving patch:
diff --git a/nautobot/users/views.py b/nautobot/users/views.py
--- a/nautobot/users/views.py
+++ b/nautobot/users/views.py
@@ -250,6 +250,7 @@ def get(self, request, pk=None):
                 "obj_type": token._meta.verbose_name,
                 "form": form,
                 "return_url": reverse("user:token_list"),
+                "editing": token.present_in_database,
             },
         )
 
@@ -283,6 +284,7 @@ def post(self, request, pk=None):
                 "obj_type": token._meta.verbose_name,
                 "form": form,
                 "return_url": reverse("user:token_list"),
+                "editing": token.present_in_database,
             },
         )
 


Test patch:
Repository: nautobot/nautobot

Issue:
Remove CSRF_TRUSTED_ORIGINS from core settings
<!--
    NOTE: This template is for use by maintainers only. Please do not submit
    an issue using this template unless you have been specifically asked to
    do so.
-->
### Proposed Changes

Remove `CSRF_TRUSTED_ORIGINS` from `nautobot.core.settings`. Replace it with revised mention of this setting in the documentation. Currently it is mentioned as being set to the same value as `ALLOWED_HOSTS` which is no longer possible due to the fact that all those values are defaults and any settings overloaded in a user's `nautobot_config.py` will not be evaluated again by values already set in `nautobot.core.settings`.

<!-- Provide justification for the proposed change(s). -->
### Justification

This is a "dynamic" setting from NetBox that has been eliminated in Nautobot. It is no longer accurate as documented.


Discussion:

Resolving patch:
diff --git a/nautobot/core/settings.py b/nautobot/core/settings.py
--- a/nautobot/core/settings.py
+++ b/nautobot/core/settings.py
@@ -70,7 +70,7 @@
 # by specifying the model individually in the EXEMPT_VIEW_PERMISSIONS configuration parameter.
 EXEMPT_EXCLUDE_MODELS = (
     ("auth", "group"),
-    ("auth", "user"),
+    ("users", "user"),
     ("users", "objectpermission"),
 )
 
@@ -282,6 +282,7 @@
 
 # Default overrides
 ALLOWED_HOSTS = []
+CSRF_TRUSTED_ORIGINS = []
 DATETIME_FORMAT = "N j, Y g:i a"
 INTERNAL_IPS = ("127.0.0.1", "::1")
 LOGGING = {}
@@ -399,8 +400,6 @@
 LOGIN_URL = "/{}login/".format(BASE_PATH)
 LOGIN_REDIRECT_URL = "/"
 
-CSRF_TRUSTED_ORIGINS = ALLOWED_HOSTS
-
 #
 # From django-cors-headers
 #


Test patch:
Repository: nautobot/nautobot

Issue:
Cable path tracing does not work with data imported by nautobot-netbox-importer (KeyError)
<!--
    NOTE: IF YOUR ISSUE DOES NOT FOLLOW THIS TEMPLATE, IT WILL BE CLOSED.

    This form is only for reporting reproducible bugs. If you need assistance
    with Nautobot installation, or if you have a general question, please start a
    discussion instead: https://github.com/nautobot/nautobot/discussions

    Please describe the environment in which you are running Nautobot. Be sure
    that you are running an unmodified instance of the latest stable release
    before submitting a bug report, and that any plugins have been disabled.
-->
### Environment
* Python version: any
* Nautobot version: 1.0.0b3

<!--
    Describe in detail the exact steps that someone else can take to reproduce
    this bug using the current stable release of Nautobot. Begin with the
    creation of any necessary database objects and call out every operation
    being performed explicitly. If reporting a bug in the REST API, be sure to
    reconstruct the raw HTTP request(s) being made: Don't rely on a client
    library such as pynautobot.
-->
### Steps to Reproduce
1. Install Nautobot 1.0.0b3
2. Install the `nautobot-netbox-importer` plugin
3. Import data from NetBox using the importer
4. In the Nautobot web UI, navigate to the Device detail view for a Device that has connected interfaces, and attempt to access the `Interfaces` tab.

<!-- What did you expect to happen? -->
### Expected Behavior

The page should load successfully, including cable traces for any connected interfaces.

<!-- What happened instead? -->
### Observed Behavior

Nautobot throws a KeyError:

```
  File "/usr/local/lib/python3.7/site-packages/nautobot/dcim/models/cables.py", line 465, in get_path
    path.append(prefetched[ct_id][object_id])
```



Discussion:

Resolving patch:
diff --git a/nautobot/core/api/serializers.py b/nautobot/core/api/serializers.py
--- a/nautobot/core/api/serializers.py
+++ b/nautobot/core/api/serializers.py
@@ -84,7 +84,7 @@ def to_internal_value(self, data):
             # PK of related object
             try:
                 # Ensure the pk is a valid UUID
-                pk = uuid.UUID(str(data), version=4)
+                pk = uuid.UUID(str(data))
             except (TypeError, ValueError):
                 raise ValidationError(
                     "Related objects must be referenced by ID or by dictionary of attributes. Received an "
diff --git a/nautobot/dcim/utils.py b/nautobot/dcim/utils.py
--- a/nautobot/dcim/utils.py
+++ b/nautobot/dcim/utils.py
@@ -13,7 +13,7 @@ def decompile_path_node(repr):
     ct_id, object_id = repr.split(":")
     # The value is stored as a string, but the lookup later uses UUID objects as keys so we convert it now.
     # Note that the content type ID is still an integer because we have no control over that model.
-    return int(ct_id), uuid.UUID(object_id, version=4)
+    return int(ct_id), uuid.UUID(object_id)
 
 
 def object_to_path_node(obj):


Test patch: