question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

viz.get_3d_backend() should return None if no 3d backend was found, instead of raising an exception

See original GitHub issue

Describe the problem

Currently, mne.viz.get_3d_backend() will raise a RuntimeError if no usable backend has been found:

https://github.com/mne-tools/mne-python/blob/d0b8bcf5201d7b5c278e7410e4035dc5aead30b8/mne/viz/backends/renderer.py#L119-L147

Describe your solution

I believe it should return None instead: if there is currently no 3d backend, then, well, there is none 😉

Describe possible alternatives

I currently have to be ready to catch a RuntimeError when I simply want to query whether I can produce a 3d visualization or not. Background: I’m plotting STCs in environments that sometimes don’t have working pyvista or mayavi installations. I want to find out when that’s the case, and switch to using matplotlib instead.

Additional context

I checked how get_3d_backend() is currently used, and without exception, any use is a comparison likeif get_3d_backend() != 'pyvista':; therefore, returning None if no working backend was found should not break any existing code.

cc @GuillaumeFavelier

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
GuillaumeFaveliercommented, Apr 28, 2020

I’ll open a PR to take care of it then 😃

1reaction
hoechenbergercommented, Apr 28, 2020

have_3d_backend() sounds good to me. So this function would return True is there is a valid 3d backend and False otherwise, right?

That would be the idea, yes 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Raise exception vs. return None in functions? - python
Are you expecting to always find a latest file? Raise an exception. And yes, re-raising a more appropriate exception is fine. If this...
Read more >
Guidelines for returning None vs. raising Error for Python ...
I would definitely go for the return None option. Raising an exception may increase readability (although I doubt it) on the function itself ......
Read more >
Do I raise or return errors in Python? - victoria.dev
Raise can help you avoid writing functions that fail silently. For example, this code will not raise an exception if JAM doesn't exist:....
Read more >
Exception Handling in LLVM — LLVM 16.0.0git documentation
When an exception is thrown in LLVM code, the runtime does its best to find a handler suited to processing the circumstance. The...
Read more >
Exception Handling — Python 3.11.1 documentation
This is a convenience function to raise WindowsError . If called with ierr of 0 , the error code returned by a call...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found