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: make gdal.UseExceptions() default to True #7452

Open
hobu opened this issue Mar 15, 2023 · 6 comments
Open

Python: make gdal.UseExceptions() default to True #7452

hobu opened this issue Mar 15, 2023 · 6 comments
Assignees
Milestone

Comments

@hobu
Copy link
Contributor

hobu commented Mar 15, 2023

It's been more than 15 years since UseExceptions was introduced with a default to False to preserve backward compatibility with the ancient GDAL Python bindings.

It is now time that those programmers who still have code depending on GDAL's behavior of not throwing need to update their code.

@rouault
Copy link
Member

rouault commented Mar 15, 2023

The biggest hurdle will be GDAL's autotest suite, that relies on not-throwing in a likely big number of places.
I guess the reasonable thing to do would be to have autotest run with gdal.DontUseExceptions() by default, and convert test files one by one to make them work properly with gdal.UseExceptions()

GDAL Python scripts will likely need changes to make them work with exceptions enabled

@dbaston
Copy link
Member

dbaston commented Mar 15, 2023

One way to help users with the transition might be to put a check in, say, gdal.Open that prints a warning if neither gdal.UseExceptions() nor gdal.DontUseExceptions() has not been called. I think it's well documented to call gdal.UseExceptions() if exceptions are wanted. I'm not sure an expectation has been communicated that people should call gdal.DontUseExceptions() if they don't want them.

@rouault rouault self-assigned this Mar 17, 2023
@neilflood
Copy link
Contributor

On a related note, a little while ago I added a context manager called ExceptionMgr to make it much easier to switch between the two states. #6637
That may help with the process of converting.

I would also have loved exceptions to be on by default, but it feels like a huge job to change over.

@rouault
Copy link
Member

rouault commented Mar 22, 2023

That may help with the process of converting.

It's heavily used in #7475

@neilflood
Copy link
Contributor

That may help with the process of converting.

It's heavily used in #7475

Ah, very good! :-)

@rouault rouault added this to the 4.0 milestone Mar 24, 2023
@rouault
Copy link
Member

rouault commented Mar 24, 2023

Assigning milestone 4.0 for that one. In PR #7452, we set some grounds to make that happen

@rouault rouault changed the title Make gdal.UseExceptions() default to True Python: make gdal.UseExceptions() default to True Sep 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants