Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python ogr.Buffer lost named kwargs. #11516

Open
schwehr opened this issue Dec 18, 2024 · 3 comments
Open

Python ogr.Buffer lost named kwargs. #11516

schwehr opened this issue Dec 18, 2024 · 3 comments
Assignees
Labels
api_abi_break Change resulting in API/ABI break bug python bindings

Comments

@schwehr
Copy link
Member

schwehr commented Dec 18, 2024

What is the bug?

3632b72 / #9924 changed ogr.i triggering a change in the interface to Buffer dropping kargs.

-    def Buffer(self, *args, **kwargs):
+    def Buffer(self, *args):
         r"""
         Buffer(Geometry self, double distance, int quadsecs=30) -> Geometry
+        Buffer(Geometry self, double distance, char ** options) -> Geometry

That means that:

  1. calls like .Buffer(distance=a_value, quadsecs=another_val) no longer work.
  2. there are two conflicting first line summaries in the doc string
diff --git a/swig/include/ogr.i b/swig/include/ogr.i
index bf31e04663..a176f12fee 100644
--- a/swig/include/ogr.i
+++ b/swig/include/ogr.i
@@ -3705,13 +3705,17 @@ public:
   }
 
   %newobject Buffer;
-#ifndef SWIGJAVA
+#if !defined(SWIGJAVA) && !defined(SWIGPYTHON)
   %feature("kwargs") Buffer;
 #endif
   OGRGeometryShadow* Buffer( double distance, int quadsecs=30 ) {
     return (OGRGeometryShadow*) OGR_G_Buffer( self, distance, quadsecs );
   }
 
+  OGRGeometryShadow* Buffer( double distance, char** options ) {
+    return (OGRGeometryShadow*) OGR_G_BufferEx( self, distance, options );
+  }
+
 %apply Pointer NONNULL {OGRGeometryShadow* other};
   %newobject Intersection;
   OGRGeometryShadow* Intersection( OGRGeometryShadow* other ) {

This triggered a change in ogr.py:

--- swig/python/osgeo/ogr.py
+++ swig/python/osgeo/ogr.py
@@ -5674,9 +5674,10 @@
         r"""RemoveLowerDimensionSubGeoms(Geometry self) -> Geometry"""
         return _ogr.Geometry_RemoveLowerDimensionSubGeoms(self, *args)
 
-    def Buffer(self, *args, **kwargs):
+    def Buffer(self, *args):
         r"""
         Buffer(Geometry self, double distance, int quadsecs=30) -> Geometry
+        Buffer(Geometry self, double distance, char ** options) -> Geometry
 
         Compute buffer of geometry.
 
@@ -5690,6 +5691,9 @@
         quadsecs: int, default=30
             The number of segments used to approximate a 90 degree
             (quadrant) of curvature.
+        options: list/dict
+            An optional list of options to control the buffer output.
+            See :cpp:func:`OGR_G_BufferEx`.
 
         Returns
         --------
@@ -5697,7 +5701,7 @@
             The newly created geometry or None if an error occurs.
 
         """
-        return _ogr.Geometry_Buffer(self, *args, **kwargs)
+        return _ogr.Geometry_Buffer(self, *args)
 
     def Intersection(self, *args):
         r"""

Steps to reproduce the issue

Build the python swig bindings before and after 3632b72.

Versions and provenance

I reproduced on a Debian testing based distribution with SWIG Version 4.2.1.

Additional context

No response

@schwehr schwehr added bug python bindings api_abi_break Change resulting in API/ABI break labels Dec 18, 2024
@schwehr schwehr changed the title Python ogr.Buffer lost named args. Python ogr.Buffer lost named kwargs. Dec 18, 2024
@schwehr
Copy link
Member Author

schwehr commented Dec 18, 2024

I see that this specific case was discussed in #9924 and the conclusion was to break kwargs. So maybe this bug is just about the confusing doc string. And is that even solvable?

@rouault
Copy link
Member

rouault commented Dec 18, 2024

is that even solvable?

we could potentially write a Python override that does the dispatching. The question is do we want to bother doing that, or just acknowledge the API break and move one. I'd be tempted for the later. That said, at a minimum we probably need to clarify the documentation that quadsecs is not a valid kwarg.

@schwehr
Copy link
Member Author

schwehr commented Dec 18, 2024

+1 for the later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api_abi_break Change resulting in API/ABI break bug python bindings
Projects
None yet
Development

No branches or pull requests

3 participants