nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: quora/pyanalyze
Pull request #455 (2022-01-31 02:30:47)

Treat Thrift enums as compatible with int


Patch:
diff --git a/docs/changelog.md b/docs/changelog.md
index 8c51c02..a61a44b 100644
--- a/docs/changelog.md
+++ b/docs/changelog.md
@@ -2,6 +2,7 @@
 
 ## Unreleased
 
+- Treat Thrift enums as compatible with `int` (#455)
 - Fix treatment of `TypeVar` with bounds or constraints
   as callables (#454)
 - Improve `TypeVar` solution algorithm (#453)
diff --git a/pyanalyze/type_object.py b/pyanalyze/type_object.py
index 904d132..2c56765 100644
--- a/pyanalyze/type_object.py
+++ b/pyanalyze/type_object.py
@@ -67,6 +67,8 @@ class TypeObject:
             self.base_classes.add(complex)
         if self.typ is float:
             self.base_classes.add(complex)
+        if self.is_thrift_enum:
+            self.base_classes.add(int)
 
     def is_assignable_to_type(self, typ: type) -> bool:
         for base in self.base_classes:


Test patch:
diff --git a/pyanalyze/test_thrift_enum.py b/pyanalyze/test_thrift_enum.py
index e31647e..c0e393f 100644
--- a/pyanalyze/test_thrift_enum.py
+++ b/pyanalyze/test_thrift_enum.py
@@ -18,6 +18,9 @@ class TestThriftEnum(TestNameCheckVisitorBase):
         def want_enum(e: ThriftEnum):
             pass
 
+        def want_int(i: int):
+            pass
+
         def capybara(e: ThriftEnum):
             want_enum(e)
             want_enum(ThriftEnum.X)
@@ -26,6 +29,8 @@ class TestThriftEnum(TestNameCheckVisitorBase):
             want_enum(1)
             want_enum(42)  # E: incompatible_argument
             want_enum(str(e))  # E: incompatible_argument
+            want_int(e)
+            want_int(e.X)
 
     @assert_passes()
     def test_typevar(self):
Repository: quora/pyanalyze
Pull request #467 (2022-02-06 16:57:19)

Do not strip away generic parameters explicitly set to `Any`


Patch:
diff --git a/docs/changelog.md b/docs/changelog.md
index 365819b..c6c0460 100644
--- a/docs/changelog.md
+++ b/docs/changelog.md
@@ -2,6 +2,8 @@
 
 ## Unreleased
 
+- Do not strip away generic parameters explicitly set to
+  `Any` (#467)
 - Fix bug that led to some overloaded calls incorrectly
   resolving to `Any` (#462)
 - Support `__init__` and `__new__` signatures from typeshed (#429)
diff --git a/pyanalyze/annotations.py b/pyanalyze/annotations.py
index 3fd0c9f..45b1b42 100644
--- a/pyanalyze/annotations.py
+++ b/pyanalyze/annotations.py
@@ -1069,8 +1069,6 @@ def _value_of_origin_args(
         origin = _maybe_get_extra(origin)
         if args:
             args_vals = [_type_from_runtime(val, ctx) for val in args]
-            if all(isinstance(val, AnyValue) for val in args_vals):
-                return _maybe_typed_value(origin)
             return GenericValue(origin, args_vals)
         else:
             return _maybe_typed_value(origin)


Test patch:
diff --git a/pyanalyze/test_annotations.py b/pyanalyze/test_annotations.py
index d172d10..84e9036 100644
--- a/pyanalyze/test_annotations.py
+++ b/pyanalyze/test_annotations.py
@@ -75,11 +75,12 @@ class TestAnnotations(TestNameCheckVisitorBase):
 
     @assert_passes()
     def test_generic(self):
-        from typing import List
+        from typing import List, Any
 
-        def capybara(x: List[int], y: List) -> None:
+        def capybara(x: List[int], y: List, z: List[Any]) -> None:
             assert_is_value(x, GenericValue(list, [TypedValue(int)]))
             assert_is_value(y, TypedValue(list))
+            assert_is_value(z, GenericValue(list, [AnyValue(AnySource.explicit)]))
 
     @assert_passes()
     def test_supports_int(self):
Repository: quora/pyanalyze
Pull request #468 (2022-02-06 22:22:43)

Detect incorrect key types passed to `dict.__getitem__`


Patch:
diff --git a/docs/changelog.md b/docs/changelog.md
index eba61c7..24bdbfb 100644
--- a/docs/changelog.md
+++ b/docs/changelog.md
@@ -2,6 +2,7 @@
 
 ## Unreleased
 
+- Detect incorrect key types passed to `dict.__getitem__` (#468)
 - Pick up the signature of `open()` from typeshed correctly (#463)
 - Do not strip away generic parameters explicitly set to
   `Any` (#467)
diff --git a/pyanalyze/implementation.py b/pyanalyze/implementation.py
index a0c7390..b16add7 100644
--- a/pyanalyze/implementation.py
+++ b/pyanalyze/implementation.py
@@ -535,6 +535,15 @@ def _dict_getitem_impl(ctx: CallContext) -> ImplReturn:
                 return AnyValue(AnySource.error)
             return val
         elif isinstance(self_value, TypedValue):
+            key_type = self_value.get_generic_arg_for_type(dict, ctx.visitor, 0)
+            can_assign = key_type.can_assign(key, ctx.visitor)
+            if isinstance(can_assign, CanAssignError):
+                ctx.show_error(
+                    f"Dictionary does not accept keys of type {key}",
+                    error_code=ErrorCode.incompatible_argument,
+                    detail=str(can_assign),
+                    arg="key",
+                )
             return self_value.get_generic_arg_for_type(dict, ctx.visitor, 1)
         else:
             return AnyValue(AnySource.inference)
diff --git a/pyanalyze/stacked_scopes.py b/pyanalyze/stacked_scopes.py
index f59df03..8af61aa 100644
--- a/pyanalyze/stacked_scopes.py
+++ b/pyanalyze/stacked_scopes.py
@@ -947,8 +947,8 @@ class FunctionScope(Scope):
     name_to_current_definition_nodes: SubScope
     usage_to_definition_nodes: Dict[Tuple[Node, Varname], List[Node]]
     definition_node_to_value: Dict[Node, Value]
-    name_to_all_definition_nodes: Dict[str, Set[Node]]
-    name_to_composites: Dict[str, Set[CompositeVariable]]
+    name_to_all_definition_nodes: Dict[Varname, Set[Node]]
+    name_to_composites: Dict[Varname, Set[CompositeVariable]]
     referencing_value_vars: Dict[Varname, Value]
     accessed_from_special_nodes: Set[Varname]
     current_loop_scopes: List[SubScope]


Test patch:
diff --git a/pyanalyze/test_implementation.py b/pyanalyze/test_implementation.py
index f8447a2..3180b8a 100644
--- a/pyanalyze/test_implementation.py
+++ b/pyanalyze/test_implementation.py
@@ -1078,6 +1078,8 @@ class TestDictGetItem(TestNameCheckVisitorBase):
             assert_is_value(nd[1], TypedValue(str))
             assert_is_value(rev[1], TypedValue(str))
 
+            dct[1]  # E: incompatible_argument
+
 
 class TestDictSetItem(TestNameCheckVisitorBase):
     @assert_passes()
Repository: huggingface/huggingface_hub
Pull request #822 (2022-04-06 09:32:44)

FIX don't raise if name/organizaiton are passed postionally
Fixes https://github.com/huggingface/huggingface_hub/issues/821

If user passes `name` as a positional argument and pass `organization` as well, we fail, whereas we should raise a `FutureWarning`.

cc @LysandreJik @osanseviero 

This needs to be backported to 0.5.1 for a patch release.

HuggingFaceDocBuilderDev: The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/huggingface_hub/pr_822). All of your documentation changes will be reflected on that endpoint.

Patch:
diff --git a/src/huggingface_hub/hf_api.py b/src/huggingface_hub/hf_api.py
index 2e0f9bec..8c2be0fb 100644
--- a/src/huggingface_hub/hf_api.py
+++ b/src/huggingface_hub/hf_api.py
@@ -58,6 +58,13 @@ logger = logging.get_logger(__name__)
 # TODO: remove after deprecation period is over (v0.7)
 def _validate_repo_id_deprecation(repo_id, name, organization):
     """Returns (name, organization) from the input."""
+    if repo_id and not name and organization:
+        # this means the user had passed name as positional, now mapped to
+        # repo_id and is passing organization as well. This wouldn't be an
+        # issue if they pass everything as kwarg. So we switch the parameters
+        # here:
+        repo_id, name = name, repo_id
+
     if not (repo_id or name):
         raise ValueError(
             "No name provided. Please pass `repo_id` with a valid repository name."


Test patch:
diff --git a/tests/test_hf_api.py b/tests/test_hf_api.py
index c76863e7..beccebbe 100644
--- a/tests/test_hf_api.py
+++ b/tests/test_hf_api.py
@@ -227,6 +227,14 @@ def test_validate_repo_id_deprecation():
             repo_id="repo_id", name="name", organization="organization"
         )
 
+    # regression test for
+    # https://github.com/huggingface/huggingface_hub/issues/821
+    with pytest.warns(FutureWarning, match="input arguments are deprecated"):
+        name, org = _validate_repo_id_deprecation(
+            repo_id="repo", name=None, organization="org"
+        )
+        assert name == "repo" and org == "org"
+
 
 @retry_endpoint
 def test_name_org_deprecation_warning():
Repository: huggingface/huggingface_hub
Pull request #913 (2022-06-16 19:32:11)

Constant was accidentally removed during deprecation transition
This constant was available before the deprecation notice, so it should be available during the warning transition period.
Note that the sentence-transformers library makes use of this constant [link to code](https://github.com/UKPLab/sentence-transformers/blob/3433c001e5a9e0991ea09e85f8861f38eb0d6583/sentence_transformers/util.py#L407)

lyle-nel: @LysandreJik I can't account for why the coverage checks would fail. The test clearly covers the bug that we are fixing here. Any thoughts?

Patch:
diff --git a/src/huggingface_hub/snapshot_download.py b/src/huggingface_hub/snapshot_download.py
index 888fcc1d..7e449255 100644
--- a/src/huggingface_hub/snapshot_download.py
+++ b/src/huggingface_hub/snapshot_download.py
@@ -12,3 +12,4 @@ warnings.warn(
 )
 
 from ._snapshot_download import *  # noqa
+from .constants import REPO_ID_SEPARATOR  # noqa


Test patch:
diff --git a/tests/test_snapshot_download.py b/tests/test_snapshot_download.py
index 09a4c75b..89714ad3 100644
--- a/tests/test_snapshot_download.py
+++ b/tests/test_snapshot_download.py
@@ -358,3 +358,7 @@ def test_snapshot_download_import():
         from huggingface_hub.snapshot_download import snapshot_download as x  # noqa
 
     assert x is snapshot_download
+
+
+def test_snapshot_download_import_constant_not_raise():
+    from huggingface_hub.snapshot_download import REPO_ID_SEPARATOR  # noqa
Repository: memorysafety/sudo-rs
Pull request #167 (2023-03-28 22:52:57)

Increase test coverage
There was a missing test-case for the code path that handled `#1, #2 machine=(runas) command`; also putting `must_use` on the authorization type is probably a good idea :-)


Patch:
diff --git a/lib/sudoers/src/policy.rs b/lib/sudoers/src/policy.rs
index 6224934c..a02d01d6 100644
--- a/lib/sudoers/src/policy.rs
+++ b/lib/sudoers/src/policy.rs
@@ -16,6 +16,8 @@ pub trait Policy {
     }
 }
 
+#[must_use]
+#[cfg_attr(test, derive(Debug, PartialEq))]
 pub enum Authorization {
     Required,
     Passed,
@@ -68,3 +70,25 @@ impl PreJudgementPolicy for Sudoers {
         }
     }
 }
+
+#[cfg(test)]
+mod test {
+    use super::*;
+
+    #[test]
+    fn authority_xlat_test() {
+        use crate::Tag;
+        let mut judge: Judgement = Default::default();
+        assert_eq!(judge.authorization(), Authorization::Forbidden);
+        judge.flags = Some(Tag {
+            passwd: true,
+            ..judge.flags.unwrap_or_default()
+        });
+        assert_eq!(judge.authorization(), Authorization::Required);
+        judge.flags = Some(Tag {
+            passwd: false,
+            ..judge.flags.unwrap_or_default()
+        });
+        assert_eq!(judge.authorization(), Authorization::Passed);
+    }
+}


Test patch:
diff --git a/lib/sudoers/src/test/mod.rs b/lib/sudoers/src/test/mod.rs
index 00f68aac..b35382c8 100644
--- a/lib/sudoers/src/test/mod.rs
+++ b/lib/sudoers/src/test/mod.rs
@@ -225,6 +225,11 @@ fn permission_test() {
     pass!(["%#1466 server=(ALL:ALL) ALL"], "user" => root(), "server"; "/bin/hello");
     FAIL!(["#1466 server=(ALL:ALL) ALL"], "root" => root(), "server"; "/bin/hello");
     FAIL!(["%#1466 server=(ALL:ALL) ALL"], "root" => root(), "server"; "/bin/hello");
+    pass!(["#1466,#1234,foo server=(ALL:ALL) ALL"], "user" => root(), "server"; "/bin/hello");
+    pass!(["#1234,foo,#1466 server=(ALL:ALL) ALL"], "user" => root(), "server"; "/bin/hello");
+    pass!(["foo,#1234,#1466 server=(ALL:ALL) ALL"], "user" => root(), "server"; "/bin/hello");
+    FAIL!(["foo,#1234,#1366 server=(ALL:ALL) ALL"], "user" => root(), "server"; "/bin/hello");
+    FAIL!(["#1366,#1234,foo server=(ALL:ALL) ALL"], "user" => root(), "server"; "/bin/hello");
     pass!(["user ALL=(ALL:#1466) /bin/foo"], "user" => request! { root, root }, "server"; "/bin/foo");
     FAIL!(["user ALL=(ALL:#1466) /bin/foo"], "user" => request! { root, other }, "server"; "/bin/foo");
     pass!(["user ALL=(ALL:#1466) /bin/foo"], "user" => request! { root, user }, "server"; "/bin/foo");