pygris icon indicating copy to clipboard operation
pygris copied to clipboard

Dummy cb parameter for geographic types with only one option

Open itendswells opened this issue 4 months ago • 1 comments

Almost all of the functions to get geometry data have a 'cb' parameter to select between TIGER files and cartographic boundary files. However geography types that only have one option like blocks() or nation() don't have this parameter.

I understand that the parameter is unnecessary for these functions, however it creates a problem when trying to write wrapper functions that can be called consistently across all of the pygris geography functions.

The 'cb' parameter is the only one I've found so far that isn't in all of them, but it's possible this could be an issue for other optional parameters like resolution, protocol, etc.

Adding in a dummy 'cb' parameter to all of these functions for consistency would be greatly appreciated, thanks!

itendswells avatar Aug 01 '25 20:08 itendswells

Is this something you can handle from your application?

def alway_allow_for_cb(func):
    def wrapper(*args, **kwargs):
        try:
            result = func(*args, **kwargs)
        except Exception as e:
            kwargs.pop("cb")
            result = func(*args, **kwargs)
        return result

    return wrapper


def func_with_cb(x, y, cb=None):
    if cb:
        print("Using cb")
    return x + y


@alway_allow_for_cb
def func_without_cb(x, y):
    return x * y


if __name__ == "__main__":
    func_with_cb(2, 3, cb=True)
    func_without_cb(2, 3, cb=True)

    # Or 
    import pygris
    blocks = always_allow_for_cb(pygris.blocks)

williambdean avatar Sep 26 '25 12:09 williambdean