nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: gorakhargosh/watchdog
Pull request #818 (2021-07-18 08:54:51)

Fix SkipRepeatsQueue._put() raises AttributeError (#817)
This fixes an issue with `SkipRepeatsQueue._put()` which causes it to raise
an `AttributeError` on the first put. This is done by adding a check to test
if `_last_item` is set to `None`, which is the value set by `__init__()`

Issue: https://github.com/gorakhargosh/watchdog/issues/817

BoboTiG: Do you mind adding a regression test?
AndreiB97: I have added a test to check for this to the commit.

Patch:
diff --git a/changelog.rst b/changelog.rst
index 776d8bf..5e7ea21 100644
--- a/changelog.rst
+++ b/changelog.rst
@@ -10,7 +10,8 @@ Changelog
 
 - [watchmedo] Fix usage of ``os.setsid()`` and ``os.killpg()`` Unix-only functions.  (`#809 <https://github.com/gorakhargosh/watchdog/pull/809>`_)
 - [mac] Fix missing ``FileModifiedEvent`` on permission or ownership changes of a file.  (`#809 <https://github.com/gorakhargosh/watchdog/pull/814>`_)
-- Thanks to our beloved contributors: @replabrobin, @BoboTiG, @SamSchott
+- [mac] Fix a possible ``AttributeError`` in ``SkipRepeatsQueue._put()``.  (`#818 <https://github.com/gorakhargosh/watchdog/pull/818>`_)
+- Thanks to our beloved contributors: @replabrobin, @BoboTiG, @SamSchott, @AndreiB97
 
 2.1.3
 ~~~~~
diff --git a/src/watchdog/utils/bricks.py b/src/watchdog/utils/bricks.py
index 35426b7..0a7e1cd 100644
--- a/src/watchdog/utils/bricks.py
+++ b/src/watchdog/utils/bricks.py
@@ -87,7 +87,7 @@ def _init(self, maxsize):
         self._last_item = None
 
     def _put(self, item):
-        if item != self._last_item:
+        if self._last_item is None or item != self._last_item:
             super()._put(item)
             self._last_item = item
         else:


Test patch:
diff --git a/tests/test_skip_repeats_queue.py b/tests/test_skip_repeats_queue.py
index be03a80..9954a4a 100644
--- a/tests/test_skip_repeats_queue.py
+++ b/tests/test_skip_repeats_queue.py
@@ -16,6 +16,7 @@
 # limitations under the License.
 
 import pytest
+import watchdog.events as events
 from watchdog.utils.bricks import SkipRepeatsQueue
 
 from .markers import cpython_only
@@ -58,6 +59,18 @@ def test_allow_nonconsecutive():
     assert q.empty()
 
 
+def test_put_with_watchdog_events():
+    # FileSystemEvent.__ne__() uses the key property without
+    # doing any type checking. Since _last_item is set to
+    # None in __init__(), an AttributeError is raised when
+    # FileSystemEvent.__ne__() tries to use None.key
+    queue = SkipRepeatsQueue()
+    dummy_file = 'dummy.txt'
+    event = events.FileCreatedEvent(dummy_file)
+    queue.put(event)
+    assert queue.get() is event
+
+
 def test_prevent_consecutive():
     q = SkipRepeatsQueue()
Repository: gorakhargosh/watchdog
Pull request #831 (2021-08-22 10:57:30)

convert regexes of type str to list
when type `str` is passed to the `regexes` argument, convert the `str` to a `list` and iterate through the list instead of iterating through `str`.

BoboTiG: Thanks @unique1o1 !

Could you add a test and a line in the changelog + your GitHub nickname?
unique1o1: > Thanks @unique1o1 !
> 
> Could you add a test and a line in the changelog + your GitHub nickname?

Done.

Patch:
diff --git a/changelog.rst b/changelog.rst
index c16de1d..abc1cb0 100644
--- a/changelog.rst
+++ b/changelog.rst
@@ -8,8 +8,8 @@ Changelog
 
 2021-xx-xx • `full history <https://github.com/gorakhargosh/watchdog/compare/v2.1.4...master>`__
 
--
-- Thanks to our beloved contributors: @
+- convert regexes of type str to list. (`#831 <https://github.com/gorakhargosh/watchdog/pull/831>`_)
+- Thanks to our beloved contributors: @unique1o1
 
 2.1.4
 ~~~~~
diff --git a/src/watchdog/events.py b/src/watchdog/events.py
index 2682366..a3baab6 100755
--- a/src/watchdog/events.py
+++ b/src/watchdog/events.py
@@ -418,6 +418,8 @@ def __init__(self, regexes=None, ignore_regexes=None,
 
         if regexes is None:
             regexes = [r".*"]
+        elif isinstance(regexes, str):
+            regexes = [regexes]
         if ignore_regexes is None:
             ignore_regexes = []
         if case_sensitive:


Test patch:
diff --git a/tests/test_regex_matching_event_handler.py b/tests/test_regex_matching_event_handler.py
index b265f08..811edf3 100644
--- a/tests/test_regex_matching_event_handler.py
+++ b/tests/test_regex_matching_event_handler.py
@@ -35,6 +35,7 @@
 path_1 = '/path/xyz'
 path_2 = '/path/abc'
 g_allowed_regexes = [r".*\.py", r".*\.txt"]
+g_allowed_str_regexes = r".*\.py"
 g_ignore_regexes = [r".*\.pyc"]
 
 
@@ -186,6 +187,12 @@ def test_regexes():
     assert [r.pattern for r in handler1.regexes] == g_allowed_regexes
 
 
+def test_str_regexes():
+    handler1 = RegexMatchingEventHandler(g_allowed_str_regexes,
+                                         g_ignore_regexes, True)
+    assert [r.pattern for r in handler1.regexes] == [g_allowed_str_regexes]
+
+
 def test_logging_event_handler_dispatch():
 
     class _TestableEventHandler(LoggingEventHandler):
Repository: gorakhargosh/watchdog
Pull request #1088 (2024-11-18 18:07:13)

Inotify's symlink follow with recursive option
* Using symlink follow now working as intended with recursive (used to be shallow only)
* Add test for recursive + follow symlink for Inotify observer
* Improve test for recursive cases : in case of recursive Inotify, directory open event always triggers first


Patch:
diff --git a/src/watchdog/observers/inotify_c.py b/src/watchdog/observers/inotify_c.py
index c8c641b..d52ec3d 100644
--- a/src/watchdog/observers/inotify_c.py
+++ b/src/watchdog/observers/inotify_c.py
@@ -408,7 +408,7 @@ def _add_dir_watch(self, path: bytes, mask: int, *, recursive: bool) -> None:
             raise OSError(errno.ENOTDIR, os.strerror(errno.ENOTDIR), path)
         self._add_watch(path, mask)
         if recursive:
-            for root, dirnames, _ in os.walk(path):
+            for root, dirnames, _ in os.walk(path, followlinks=self._follow_symlink):
                 for dirname in dirnames:
                     full_path = os.path.join(root, dirname)
                     if not self._follow_symlink and os.path.islink(full_path):


Test patch:
diff --git a/tests/test_inotify_buffer.py b/tests/test_inotify_buffer.py
index 067b913..e845f92 100644
--- a/tests/test_inotify_buffer.py
+++ b/tests/test_inotify_buffer.py
@@ -11,7 +11,8 @@
 import random
 import time
 
-from watchdog.observers.inotify_buffer import InotifyBuffer
+from watchdog.observers.inotify_c import InotifyConstants
+from watchdog.observers.inotify_buffer import InotifyBuffer, InotifyEvent
 
 from .shell import mkdir, mount_tmpfs, mv, rm, symlink, touch, unmount
 
@@ -126,7 +127,29 @@ def test_delete_watched_directory_symlink_followed(p):
     rm(p("dir", "dir2"), recursive=True)
 
     # Wait for the event to be picked up
-    inotify.read_event()
+    event = inotify.read_event()
+    while not isinstance(event, InotifyEvent) or (
+            event.mask != (InotifyConstants.IN_DELETE | InotifyConstants.IN_ISDIR)):
+        event = inotify.read_event()
+
+    # Ensure InotifyBuffer shuts down cleanly without raising an exception
+    inotify.close()
+
+
+@pytest.mark.timeout(5)
+def test_delete_watched_directory_symlink_followed_recursive(p):
+    mkdir(p("dir"), parents=True)
+    mkdir(p("dir2", "dir3", "dir4"), parents=True)
+    symlink(p("dir2"), p("dir", "symdir"), target_is_directory=True)
+
+    inotify = InotifyBuffer(p("dir").encode(), follow_symlink=True, recursive=True)
+    rm(p("dir2", "dir3", "dir4"), recursive=True)
+
+    # Wait for the event to be picked up
+    event = inotify.read_event()
+    while not isinstance(event, InotifyEvent) or (
+            event.mask != (InotifyConstants.IN_DELETE | InotifyConstants.IN_ISDIR)):
+        event = inotify.read_event()
 
     # Ensure InotifyBuffer shuts down cleanly without raising an exception
     inotify.close()
Repository: pingcap/pd
Pull request #743 (2017-09-11 00:25:10)

server: make raft tick configurable
Make raft tick and election configurable. 
In some test like jepsen, we need to use a small raft tick and election.

PTAL @disksing @huachaohuang 

disksing: /ok-to-test
disksing: /run-full-test
disksing: LGTM.
disksing: /run-all-test tikv=pre-ga

Patch:
diff --git a/server/config.go b/server/config.go
index 748f56db9..67c1bcc9d 100644
--- a/server/config.go
+++ b/server/config.go
@@ -78,8 +78,10 @@ type Config struct {
 	// the default retention is 1 hour
 	AutoCompactionRetention int `toml:"auto-compaction-retention" json:"auto-compaction-retention"`
 
-	tickMs     uint64
-	electionMs uint64
+	// TickInterval is the interval for etcd Raft tick.
+	TickInterval typeutil.Duration `toml:"tick-interval"`
+	// ElectionInterval is the interval for etcd Raft election.
+	ElectionInterval typeutil.Duration `toml:"election-interval"`
 
 	configFile string
 
@@ -132,9 +134,9 @@ const (
 	// We can enlarge both a little to reduce the network aggression.
 	// now embed etcd use TickMs for heartbeat, we will update
 	// after embed etcd decouples tick and heartbeat.
-	defaultTickMs = uint64(500)
+	defaultTickInterval = 500 * time.Millisecond
 	// embed etcd has a check that `5 * tick > election`
-	defaultElectionMs = uint64(3000)
+	defaultElectionInterval = 3000 * time.Millisecond
 )
 
 func adjustString(v *string, defValue string) {
@@ -254,8 +256,8 @@ func (c *Config) adjust() error {
 		c.AutoCompactionRetention = defaultAutoCompactionRetention
 	}
 
-	adjustUint64(&c.tickMs, defaultTickMs)
-	adjustUint64(&c.electionMs, defaultElectionMs)
+	adjustDuration(&c.TickInterval, defaultTickInterval)
+	adjustDuration(&c.ElectionInterval, defaultElectionInterval)
 
 	adjustString(&c.Metric.PushJob, c.Name)
 
@@ -433,8 +435,8 @@ func (c *Config) genEmbedEtcdConfig() (*embed.Config, error) {
 	cfg.ClusterState = c.InitialClusterState
 	cfg.EnablePprof = true
 	cfg.StrictReconfigCheck = !c.disableStrictReconfigCheck
-	cfg.TickMs = uint(c.tickMs)
-	cfg.ElectionMs = uint(c.electionMs)
+	cfg.TickMs = uint(c.TickInterval.Duration / time.Millisecond)
+	cfg.ElectionMs = uint(c.ElectionInterval.Duration / time.Millisecond)
 	cfg.AutoCompactionRetention = c.AutoCompactionRetention
 	cfg.QuotaBackendBytes = int64(c.QuotaBackendBytes)
 


Test patch:
diff --git a/server/testutil.go b/server/testutil.go
index d61b86701..734bf08fd 100644
--- a/server/testutil.go
+++ b/server/testutil.go
@@ -67,8 +67,8 @@ func NewTestSingleConfig() *Config {
 	cfg.DataDir, _ = ioutil.TempDir("/tmp", "test_pd")
 	cfg.InitialCluster = fmt.Sprintf("pd=%s", cfg.PeerUrls)
 	cfg.disableStrictReconfigCheck = true
-	cfg.tickMs = 100
-	cfg.electionMs = 1000
+	cfg.TickInterval = typeutil.NewDuration(100 * time.Millisecond)
+	cfg.ElectionInterval = typeutil.NewDuration(1000 * time.Millisecond)
 
 	cfg.adjust()
 	return cfg