nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: gtalarico/pyairtable
Pull request #323 (2023-12-09 16:10:37)

Add formulas for missing logical operators
Implements missing formulas from [section "Logical operators and functions" from documentation of "Formula field reference"](https://support.airtable.com/docs/formula-field-reference#logical-operators-and-functions). Currently only `EQUAL` is implemented.


Patch:
diff --git a/pyairtable/formulas.py b/pyairtable/formulas.py
index 09a40f7..734a4e4 100644
--- a/pyairtable/formulas.py
+++ b/pyairtable/formulas.py
@@ -218,3 +218,53 @@ def LOWER(value: str) -> str:
     "LOWER(TestValue)"
     """
     return "LOWER({})".format(value)
+
+
+def NOT_EQUAL(left: Any, right: Any) -> str:
+    """
+    Create an inequality assertion
+
+    >>> NOT_EQUAL(2,2)
+    '2!=2'
+    """
+    return "{}!={}".format(left, right)
+
+
+def LESS_EQUAL(left: Any, right: Any) -> str:
+    """
+    Create a less than assertion
+
+    >>> LESS_EQUAL(2,2)
+    '2<=2'
+    """
+    return "{}<={}".format(left, right)
+
+
+def GREATER_EQUAL(left: Any, right: Any) -> str:
+    """
+    Create a greater than assertion
+
+    >>> GREATER_EQUAL(2,2)
+    '2>=2'
+    """
+    return "{}>={}".format(left, right)
+
+
+def LESS(left: Any, right: Any) -> str:
+    """
+    Create a less assertion
+
+    >>> LESS(2,2)
+    '2<2'
+    """
+    return "{}<{}".format(left, right)
+
+
+def GREATER(left: Any, right: Any) -> str:
+    """
+    Create a greater assertion
+
+    >>> GREATER(2,2)
+    '2>2'
+    """
+    return "{}>{}".format(left, right)


Test patch:
diff --git a/tests/test_formulas.py b/tests/test_formulas.py
index 4e36a89..0736da5 100644
--- a/tests/test_formulas.py
+++ b/tests/test_formulas.py
@@ -5,8 +5,13 @@ from pyairtable.formulas import (
     EQUAL,
     FIELD,
     FIND,
+    GREATER,
+    GREATER_EQUAL,
     IF,
+    LESS,
+    LESS_EQUAL,
     LOWER,
+    NOT_EQUAL,
     OR,
     STR_VALUE,
     escape_quotes,
@@ -86,3 +91,23 @@ def test_escape_quotes(text, escaped):
 
 def test_lower():
     assert LOWER("TestValue") == "LOWER(TestValue)"
+
+
+def test_greater_equal():
+    assert GREATER_EQUAL("A", "B") == "A>=B"
+
+
+def test_less_equal():
+    assert LESS_EQUAL("A", "B") == "A<=B"
+
+
+def test_greater():
+    assert GREATER("A", "B") == "A>B"
+
+
+def test_less():
+    assert LESS("A", "B") == "A<B"
+
+
+def test_not_equal():
+    assert NOT_EQUAL("A", "B") == "A!=B"
Repository: gtalarico/pyairtable
Pull request #345 (2024-03-12 05:37:30)

Update `base.create_table`
Turn on `force` during `base.create_table` when trying to return the newly created table. The newly created table is not included in the cached tables, setting `force` to `True` makes sure to use the updated table list.

I believe this is necessary, as adding a `force` parameter to the arguments list of `base.create_table` does not make sense. I can't see any utility in not refreshing the tables list, unless we set returning the new table to optional.

See issue #343


Patch:
diff --git a/pyairtable/api/base.py b/pyairtable/api/base.py
index f11ab29..358b66d 100644
--- a/pyairtable/api/base.py
+++ b/pyairtable/api/base.py
@@ -160,7 +160,7 @@ class Base:
         if description:
             payload["description"] = description
         response = self.api.post(url, json=payload)
-        return self.table(response["id"], validate=True)
+        return self.table(response["id"], validate=True, force=True)
 
     @property
     def url(self) -> str:


Test patch:
diff --git a/tests/test_api_base.py b/tests/test_api_base.py
index 83432f4..4fadda8 100644
--- a/tests/test_api_base.py
+++ b/tests/test_api_base.py
@@ -247,6 +247,41 @@ def test_create_table(base, requests_mock, mock_tables_endpoint):
     assert table.schema().primary_field_id == "fldWasJustCreated"
 
 
+def test_schema_refresh(base, requests_mock, mock_tables_endpoint):
+    """
+    Test that base.schema() is forced to refresh on table create.
+    """
+
+    schema_id = id(base.schema())
+
+    m = requests_mock.post(mock_tables_endpoint._url, json={"id": "tblWasJustCreated"})
+    mock_tables_endpoint._responses[0]._params["json"]["tables"].append(
+        {
+            "id": "tblWasJustCreated",
+            "name": "Table Name",
+            "primaryFieldId": "fldWasJustCreated",
+            "fields": [
+                {
+                    "id": "fldWasJustCreated",
+                    "name": "Whatever",
+                    "type": "singleLineText",
+                }
+            ],
+            "views": [],
+        }
+    )
+
+    table = base.create_table(
+        "Table Name",
+        fields=[{"name": "Whatever"}],
+        description="Description",
+    )
+
+    assert m.call_count == 1
+    assert table.id == "tblWasJustCreated"
+    assert not id(base.schema()) == schema_id
+
+
 def test_delete(base, requests_mock):
     """
     Test that Base.delete() hits the right endpoint.
Repository: gtalarico/pyairtable
Pull request #349 (2024-03-15 03:22:58)

Bug fix for deprecated `metadata.get_table_schema`
Fixes the bug described in #314
Adds test case in `tests\test_api_table`


Patch:
diff --git a/pyairtable/metadata.py b/pyairtable/metadata.py
index b231eac..90e8fde 100644
--- a/pyairtable/metadata.py
+++ b/pyairtable/metadata.py
@@ -146,4 +146,6 @@ def get_table_schema(table: Table) -> Optional[Dict[Any, Any]]:  # pragma: no co
         assert isinstance(table_record, dict)
         if table.name == table_record["name"]:
             return table_record
+        if table.id == table_record["id"]:
+            return table_record
     return None


Test patch:
diff --git a/tests/test_api_table.py b/tests/test_api_table.py
index 6fa43c6..f3cad43 100644
--- a/tests/test_api_table.py
+++ b/tests/test_api_table.py
@@ -5,6 +5,7 @@ from requests import Request
 from requests_mock import Mocker
 
 from pyairtable import Api, Base, Table
+from pyairtable.metadata import get_table_schema
 from pyairtable.models.schema import TableSchema
 from pyairtable.testing import fake_id, fake_record
 from pyairtable.utils import chunked
@@ -441,6 +442,26 @@ def test_delete_view(table, mock_schema, requests_mock):
     assert m.call_count == 1
 
 
+def test_deprecated_get_schema_by_id(base, api, requests_mock, sample_json):
+    """
+    Tests the ability to get a table schema by `id` using the deprecated `pyairtable.metadata.get_table_schema`
+    """
+    mock_create = requests_mock.get(
+        base.meta_url("tables"),
+        json=sample_json("BaseSchema"),
+    )
+
+    # Test fetching schema by id
+    table = api.table(base.id, base.tables()[0].id)
+
+    # Deprecated method for getting table's schema
+    table_schema = get_table_schema(table)
+
+    assert table_schema is not None
+    assert table_schema["id"] == table.id
+    assert mock_create.call_count == 2
+
+
 # Helpers
Repository: asottile/add-trailing-comma
Pull request #19 (2017-07-15 23:30:46)

Don't unhug things containing only a triple-quoted-string


Patch:
diff --git a/add_trailing_comma.py b/add_trailing_comma.py
index 2884adf..d8f1939 100644
--- a/add_trailing_comma.py
+++ b/add_trailing_comma.py
@@ -251,9 +251,14 @@ def _fix_brace(fix_data, add_comma, tokens):
     hug_open = tokens[first_brace + 1].name not in NON_CODING_TOKENS
     hug_close = tokens[last_brace - 1].name not in NON_CODING_TOKENS
     if (
+            # Don't unhug single element things with a multi-line component
+            # inside.
             not fix_data.multi_arg and
             hug_open and
-            tokens[last_brace - 1].src in END_BRACES
+            tokens[last_brace - 1].src in END_BRACES or
+            # Don't unhug when containing a single token (such as a triple
+            # quoted string).
+            first_brace + 2 == last_brace
     ):
         hug_open = hug_close = False
 


Test patch:
diff --git a/tests/add_trailing_comma_test.py b/tests/add_trailing_comma_test.py
index 1cd26c9..01ee421 100644
--- a/tests/add_trailing_comma_test.py
+++ b/tests/add_trailing_comma_test.py
@@ -312,6 +312,10 @@ def test_fixes_defs(src, expected):
         'f([\n'
         '    1, 2, 3,\n'
         '])',
+        # Single triple-quoted-string argument, don't unhug
+        'textwrap.dedent("""\n'
+        '    hi\n'
+        '""")',
     ),
 )
 def test_noop_unhugs(src):
Repository: asottile/add-trailing-comma
Pull request #86 (2019-07-08 23:02:07)

Update assertion when min_indent is None


Patch:
diff --git a/add_trailing_comma.py b/add_trailing_comma.py
index ea579a6..ebbfb61 100644
--- a/add_trailing_comma.py
+++ b/add_trailing_comma.py
@@ -358,11 +358,12 @@ def _fix_brace(tokens, fix_data, add_comma, remove_comma):
                         min_indent = len(tokens[i].src)
                     indents.append(i)
 
-        assert min_indent is not None
-        for i in indents:
-            oldlen = len(tokens[i].src)
-            newlen = oldlen - min_indent + new_indent
-            tokens[i] = tokens[i]._replace(src=' ' * newlen)
+        if indents:
+            assert min_indent is not None
+            for i in indents:
+                oldlen = len(tokens[i].src)
+                newlen = oldlen - min_indent + new_indent
+                tokens[i] = tokens[i]._replace(src=' ' * newlen)
         for i in reversed(insert_indents):
             tokens.insert(i, Token(UNIMPORTANT_WS, ' ' * new_indent))
             last_brace += 1


Test patch:
diff --git a/tests/add_trailing_comma_test.py b/tests/add_trailing_comma_test.py
index e0c891a..b1062a2 100644
--- a/tests/add_trailing_comma_test.py
+++ b/tests/add_trailing_comma_test.py
@@ -383,6 +383,14 @@ def test_noop_unhugs(src):
             '    a,\n'
             ')',
         ),
+        (
+            'f(a\n'
+            ')',
+
+            'f(\n'
+            '    a,\n'
+            ')',
+        ),
         (
             'f(a,\n'
             '  b,\n'
Repository: asottile/add-trailing-comma
Pull request #94 (2020-03-02 00:36:47)

Also add trailing commas to posonlyargs


Patch:
diff --git a/add_trailing_comma.py b/add_trailing_comma.py
index 1069b78..29b40a6 100644
--- a/add_trailing_comma.py
+++ b/add_trailing_comma.py
@@ -117,7 +117,7 @@ class FindNodes(ast.NodeVisitor):
 
     def visit_FunctionDef(self, node: ast.FunctionDef) -> None:
         has_starargs = False
-        args = list(node.args.args)
+        args = [*getattr(node.args, 'posonlyargs', ()), *node.args.args]
 
         if node.args.vararg:
             args.append(node.args.vararg)


Test patch:
diff --git a/tests/add_trailing_comma_test.py b/tests/add_trailing_comma_test.py
index 68c9416..4b21e33 100644
--- a/tests/add_trailing_comma_test.py
+++ b/tests/add_trailing_comma_test.py
@@ -668,6 +668,25 @@ def test_fix_unhugs_py3_only(src, expected):
     assert _fix_src(src, py35_plus=False, py36_plus=False) == expected
 
 
+@pytest.mark.xfail(sys.version_info < (3, 8), reason='py38+')
+@pytest.mark.parametrize(
+    ('src', 'expected'),
+    (
+        (
+            'def f(\n'
+            '    x, /\n'
+            '): pass\n',
+
+            'def f(\n'
+            '    x, /,\n'
+            '): pass\n',
+        ),
+    ),
+)
+def test_fix_posonlyargs(src, expected):
+    assert _fix_src(src, py35_plus=False, py36_plus=False) == expected
+
+
 @pytest.mark.parametrize(
     'src',
     (
Repository: asottile/add-trailing-comma
Pull request #110 (2021-01-24 18:07:40)

add support for commas in async def


Patch:
diff --git a/README.md b/README.md
index eb50bfa..790b836 100644
--- a/README.md
+++ b/README.md
@@ -121,6 +121,14 @@ Note that this would cause a **`SyntaxError`** in earlier python versions.
  ):
 ```
 
+```diff
+ async def func(
+         arg1,
+-        arg2
++        arg2,
+ ):
+```
+
 ### trailing commas for function definitions with unpacking arguments
 
 If `--py36-plus` is passed, `add-trailing-comma` will also perform the
diff --git a/add_trailing_comma/_plugins/functions.py b/add_trailing_comma/_plugins/functions.py
index 43d2d59..8b72060 100644
--- a/add_trailing_comma/_plugins/functions.py
+++ b/add_trailing_comma/_plugins/functions.py
@@ -4,6 +4,7 @@ from typing import Iterable
 from typing import List
 from typing import Set
 from typing import Tuple
+from typing import Union
 
 from tokenize_rt import Offset
 from tokenize_rt import Token
@@ -32,10 +33,9 @@ def _fix_func(
     )
 
 
-@register(ast.FunctionDef)
 def visit_FunctionDef(
         parse_state: ParseState,
-        node: ast.FunctionDef,
+        node: Union[ast.AsyncFunctionDef, ast.FunctionDef],
 ) -> Iterable[Tuple[Offset, TokenFunc]]:
     has_starargs = False
     args = [*getattr(node.args, 'posonlyargs', ()), *node.args.args]
@@ -59,3 +59,7 @@ def visit_FunctionDef(
             arg_offsets=arg_offsets,
         )
         yield ast_to_offset(node), func
+
+
+register(ast.AsyncFunctionDef)(visit_FunctionDef)
+register(ast.FunctionDef)(visit_FunctionDef)


Test patch:
diff --git a/tests/features/functions_test.py b/tests/features/functions_test.py
index 98082e8..c49e13b 100644
--- a/tests/features/functions_test.py
+++ b/tests/features/functions_test.py
@@ -44,6 +44,15 @@ def test_noop_function_defs(src):
             '        x,\n'
             '): pass',
         ),
+        pytest.param(
+            'async def f(\n'
+            '        x\n'
+            '): pass',
+            'async def f(\n'
+            '        x,\n'
+            '): pass',
+            id='async def',
+        ),
     ),
 )
 def test_fixes_defs(src, expected):
Repository: asottile/add-trailing-comma
Pull request #214 (2022-12-12 19:43:45)

deprecate anything older than --py36-plus


Patch:
diff --git a/add_trailing_comma/_main.py b/add_trailing_comma/_main.py
index d40417f..850d967 100644
--- a/add_trailing_comma/_main.py
+++ b/add_trailing_comma/_main.py
@@ -96,6 +96,12 @@ def main(argv: Sequence[str] | None = None) -> int:
     )
     args = parser.parse_args(argv)
 
+    if args.min_version < (3, 6):
+        print(
+            'WARNING: add-trailing-comma will only use 3.6+ mod after 3.0',
+            file=sys.stderr,
+        )
+
     ret = 0
     for filename in args.filenames:
         ret |= fix_file(filename, args)


Test patch:
diff --git a/tests/main_test.py b/tests/main_test.py
index 339a239..bf66943 100644
--- a/tests/main_test.py
+++ b/tests/main_test.py
@@ -21,7 +21,7 @@ def test_main_noop(tmpdir):
 def test_main_changes_a_file(tmpdir, capsys):
     f = tmpdir.join('f.py')
     f.write('x(\n    1\n)\n')
-    assert main((f.strpath,)) == 1
+    assert main((f.strpath, '--py36-plus')) == 1
     _, err = capsys.readouterr()
     assert err == f'Rewriting {f}\n'
     assert f.read() == 'x(\n    1,\n)\n'
@@ -30,7 +30,7 @@ def test_main_changes_a_file(tmpdir, capsys):
 def test_main_preserves_line_endings(tmpdir, capsys):
     f = tmpdir.join('f.py')
     f.write_binary(b'x(\r\n    1\r\n)\r\n')
-    assert main((f.strpath,)) == 1
+    assert main((f.strpath, '--py36-plus')) == 1
     _, err = capsys.readouterr()
     assert err == f'Rewriting {f}\n'
     assert f.read_binary() == b'x(\r\n    1,\r\n)\r\n'
@@ -45,7 +45,7 @@ def test_main_syntax_error(tmpdir):
 def test_main_non_utf8_bytes(tmpdir, capsys):
     f = tmpdir.join('f.py')
     f.write_binary('# -*- coding: cp1252 -*-\nx = €\n'.encode('cp1252'))
-    assert main((f.strpath,)) == 1
+    assert main((f.strpath, '--py36-plus')) == 1
     _, err = capsys.readouterr()
     assert err == f'{f} is non-utf-8 (not supported)\n'
 
@@ -53,17 +53,21 @@ def test_main_non_utf8_bytes(tmpdir, capsys):
 def test_main_py27_syntaxerror_coding(tmpdir):
     f = tmpdir.join('f.py')
     f.write('# -*- coding: utf-8 -*-\n[1, 2,]\n')
-    assert main((f.strpath,)) == 1
+    assert main((f.strpath, '--py36-plus')) == 1
     assert f.read() == '# -*- coding: utf-8 -*-\n[1, 2]\n'
 
 
-def test_main_py35_plus_argument_star_args(tmpdir):
+def test_main_py35_plus_argument_star_args(tmpdir, capsys):
     f = tmpdir.join('f.py')
     f.write('x(\n    *args\n)\n')
     assert main((f.strpath,)) == 0
     assert f.read() == 'x(\n    *args\n)\n'
+    out, err = capsys.readouterr()
+    assert err.startswith('WARNING: add-trailing-comma will only use 3.6+')
     assert main((f.strpath, '--py35-plus')) == 1
     assert f.read() == 'x(\n    *args,\n)\n'
+    out, err = capsys.readouterr()
+    assert err.startswith('WARNING: add-trailing-comma will only use 3.6+')
 
 
 def test_main_py35_plus_argument_star_star_kwargs(tmpdir):