tvalentyn commented on code in PR #28454:
URL: https://github.com/apache/beam/pull/28454#discussion_r1327523320


##########
sdks/python/apache_beam/dataframe/frame_base.py:
##########
@@ -500,6 +500,8 @@ def wrap(func):
 
     removed_arg_names = removed_args if removed_args is not None else []
 
+    # TODO: Better handle position only arguments if they are ever a thing

Review Comment:
   Sounds like we could remove this TODO. If you think we should keep it, would 
you mind expanding on what 'better' would mean? Thanks!



##########
sdks/python/apache_beam/dataframe/frame_base_test.py:
##########
@@ -72,7 +72,7 @@ def add_one(frame):
 
   def test_args_to_kwargs(self):
     class Base(object):
-      def func(self, a=1, b=2, c=3):
+      def func(self, a=1, b=2, c=3, *, kw_only=4):

Review Comment:
   would it make sense to also include an argument without a default in this or 
antoher test case?



##########
sdks/python/apache_beam/dataframe/frame_base_test.py:
##########
@@ -129,6 +132,45 @@ def func_removed_args(self, a, c, **kwargs):
       proxy.func_removed_args()
     self.assertEqual(proxy.func_removed_args(12, d=100), {'a': 12, 'd': 100})
 
+  def test_args_to_kwargs_populates_default_handles_kw_only(self):
+    class Base(object):
+      def func(self, a=1, b=2, c=3, *, kw_only=4):
+        pass
+
+    class ProxyUsesKwOnly(object):
+      @frame_base.args_to_kwargs(Base)
+      @frame_base.populate_defaults(Base)
+      def func(self, a, kw_only, **kwargs):
+        return dict(kwargs, a=a, kw_only=kw_only)
+
+    proxy = ProxyUsesKwOnly()
+
+    # pylint: disable=too-many-function-args,no-value-for-parameter
+    self.assertEqual(proxy.func(), {'a': 1, 'kw_only': 4})
+    self.assertEqual(proxy.func(100), {'a': 100, 'kw_only': 4})
+    self.assertEqual(
+        proxy.func(2, 4, 6, kw_only=8), {
+            'a': 2, 'b': 4, 'c': 6, 'kw_only': 8
+        })
+    with self.assertRaises(TypeError):
+      proxy.func(2, 4, 6, 8)  # got too many positioned arguments
+
+    class ProxyDoesntUseKwOnly(object):
+      @frame_base.args_to_kwargs(Base)
+      @frame_base.populate_defaults(Base)
+      def func(self, a, **kwargs):
+        return dict(kwargs, a=a)
+
+    proxy = ProxyDoesntUseKwOnly()
+
+    # pylint: disable=too-many-function-args,no-value-for-parameter
+    self.assertEqual(proxy.func(), {'a': 1})

Review Comment:
   Why is it that in this case the `a=1` default is populated, but `b=2`, 
`c=3`, `kw_only=4` are not?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to