nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: crewAIInc/crewAI
Pull request #1910 (2025-01-16 20:45:38)

Fix union issue that Daniel was running into


Patch:
diff --git a/src/crewai/utilities/converter.py b/src/crewai/utilities/converter.py
index e9f8c6b8..5a797d8a 100644
--- a/src/crewai/utilities/converter.py
+++ b/src/crewai/utilities/converter.py
@@ -241,9 +241,13 @@ def generate_model_description(model: Type[BaseModel]) -> str:
         origin = get_origin(field_type)
         args = get_args(field_type)
 
-        if origin is Union and type(None) in args:
+        if origin is Union or (origin is None and len(args) > 0):
+            # Handle both Union and the new '|' syntax
             non_none_args = [arg for arg in args if arg is not type(None)]
-            return f"Optional[{describe_field(non_none_args[0])}]"
+            if len(non_none_args) == 1:
+                return f"Optional[{describe_field(non_none_args[0])}]"
+            else:
+                return f"Optional[Union[{', '.join(describe_field(arg) for arg in non_none_args)}]]"
         elif origin is list:
             return f"List[{describe_field(args[0])}]"
         elif origin is dict:
@@ -252,8 +256,10 @@ def generate_model_description(model: Type[BaseModel]) -> str:
             return f"Dict[{key_type}, {value_type}]"
         elif isinstance(field_type, type) and issubclass(field_type, BaseModel):
             return generate_model_description(field_type)
-        else:
+        elif hasattr(field_type, "__name__"):
             return field_type.__name__
+        else:
+            return str(field_type)
 
     fields = model.__annotations__
     field_descriptions = [


Test patch:
diff --git a/tests/utilities/test_converter.py b/tests/utilities/test_converter.py
index df906acd..f661af9c 100644
--- a/tests/utilities/test_converter.py
+++ b/tests/utilities/test_converter.py
@@ -588,3 +588,12 @@ def test_converter_with_function_calling():
     assert output.name == "Eve"
     assert output.age == 35
     instructor.to_pydantic.assert_called_once()
+
+
+def test_generate_model_description_union_field():
+    class UnionModel(BaseModel):
+        field: int | str | None
+
+    description = generate_model_description(UnionModel)
+    expected_description = '{\n  "field": int | str | None\n}'
+    assert description == expected_description
Repository: ember-intl/ember-intl
Pull request #1179 (2020-03-24 09:33:41)

Append context to ICU parsing failure
Without the string context it's impossible to know which ICU argument had incorrect syntax.

Let me know what you think! @jasonmit


Patch:
diff --git a/lib/broccoli/translation-reducer/utils/extract-icu-arguments.js b/lib/broccoli/translation-reducer/utils/extract-icu-arguments.js
index b621c252..23f685a2 100644
--- a/lib/broccoli/translation-reducer/utils/extract-icu-arguments.js
+++ b/lib/broccoli/translation-reducer/utils/extract-icu-arguments.js
@@ -4,10 +4,16 @@
 const parser = require('@ember-intl/intl-messageformat-parser');
 
 function extractICUArguments(string) {
-  return parser
-    .parse(string)
-    .elements.filter(element => element.type === 'argumentElement')
-    .map(argumentElement => argumentElement.id);
+  try {
+    // Errors thrown by the parser won't include any details about the string. By rethrowing the
+    // error with the string quoted it's much easier to identify which ICU argument was invalid.
+    return parser
+      .parse(string)
+      .elements.filter(element => element.type === 'argumentElement')
+      .map(argumentElement => argumentElement.id);
+  } catch (err) {
+    throw new Error(`An error occured (${err.message}) when extracting ICU arguments for '${string}'`);
+  }
 }
 
 module.exports = extractICUArguments;


Test patch:
diff --git a/tests-node/unit/broccoli/translation-reducer/index-test.js b/tests-node/unit/broccoli/translation-reducer/index-test.js
index 738d6482..8991718a 100644
--- a/tests-node/unit/broccoli/translation-reducer/index-test.js
+++ b/tests-node/unit/broccoli/translation-reducer/index-test.js
@@ -149,6 +149,13 @@ describe('translation-reducer', function() {
         }
       };
 
+      this.brokenIcuFixture = {
+        en: {
+          brokenSyntax: 'You have {count, plural, =0 {one {cat} other {several cats}}.',
+          validSyntax: 'You have {count, plural, =0 {one cat} other {several cats}.}'
+        }
+      };
+
       this.fixture = {
         de: {
           foo: 'FOO',
@@ -192,6 +199,18 @@ describe('translation-reducer', function() {
       ]);
     });
 
+    it('lintTranslations throws error for invalid ICU argument syntax', function() {
+      let subject = new TranslationReducer(this.input.path());
+
+      // this might change slightly if the parser lib is updated, if so it's fine to adjust
+      let expectedParserError = 'Expected "," or "}" but "c" found.';
+      let brokenString = this.brokenIcuFixture.en.brokenSyntax;
+
+      expect(() => subject.lintTranslations(this.brokenIcuFixture)).throws(
+        `An error occured (${expectedParserError}) when extracting ICU arguments for '${brokenString}'`
+      );
+    });
+
     it('lintTranslations returns list of icu argument mismatch', function() {
       let subject = new TranslationReducer(this.input.path());
       let { icuMismatch } = subject.lintTranslations(this.icuFixture);