aerkalov / ebooklib

Python E-book library for handling books in EPUB2/EPUB3 format -
https://ebooklib.readthedocs.io/
GNU Affero General Public License v3.0
1.49k stars 234 forks source link

Option ignore_ncx (warning) #296

Open carlosalvidrez opened 11 months ago

carlosalvidrez commented 11 months ago

Getting this warning:

ebooklib/epub.py:1395: UserWarning: In the future version we will turn default option ignore_ncx to True. warnings.warn('In the future version we will turn default option ignore_ncx to True.')

noembryo commented 11 months ago

.. and the only way to silence it is to set it True like this: epub.read_epub(filename, {"ignore_ncx": True})

I think that the intention was to explicitly select whether you want it or not, and not use the default, which is False. But, as I said it forces you to select True, otherwise you got a warning that looks really bad in a CLI.

This is because in the code, there is an if not self.options.get('ignore_ncx'): where it should be if self.options.get('ignore_ncx') is None:

paotsaq commented 9 months ago

Huh. Thanks. This was pesky. Is this something that could be solved with a PR? At least to make the comment more clear in how to suppress the warning.

noembryo commented 9 months ago

Huh. Thanks. This was pesky. Is this something that could be solved with a PR?

Yes, this is what the proposed change in the code does. It's really a very simple change and that's why I just post it here instead of creating a PR. epub.py line 1393 change if not self.options.get('ignore_ncx'): to if self.options.get('ignore_ncx') is None:

At least to make the comment more clear in how to suppress the warning.

You can't suppress the warning from your app in any other way. Only by changing the original code.

alzamer2 commented 3 months ago

Huh. Thanks. This was pesky. Is this something that could be solved with a PR?

Yes, this is what the proposed change in the code does. It's really a very simple change and that's why I just post it here instead of creating a PR. epub.py line 1393 change if not self.options.get('ignore_ncx'): to if self.options.get('ignore_ncx') is None:

At least to make the comment more clear in how to suppress the warning.

You can't suppress the warning from your app in any other way. Only by changing the original code.

will you can suppress only in your code just add these lines at start of your code

import warnings

# supress ignore_ncx

warnings.filterwarnings("ignore", message="In the future version we will turn default option ignore_ncx to True.")