On 04/04/2021 19:05, Shreyan Avigyan wrote:
When importing the curses module, be it on Windows or Darwin or UNIX-based OS 
or any other platform, if the _curses module is not found then just a 
ModuleNotFoundError is raised. But this error is not very informational in case 
of _curses module. Since the curses module is packaged with the Python 
interpreter itself at first it may seem, to beginners especially, that the 
Python interpreter was not installed correctly and then they would go searching 
for an answer for about 4-5 days.

We know that curses library is not installed on windows by default and may or 
may not be present on other operating systems. Most UNIX system have ncurses or 
other curses library installed by default.

Python errors have a reputation of being very informational. I would like to submit a PR 
to modify the curses module a little bit by declaring a BaseException class and raising 
that Exception with the message "_curses module not found. Make sure a curses 
library is installed" or some kind of message like that.

But before I do that I would like to take advice from experienced developers 
about somethings. Is this change in the exception, raised when _curses module 
is not found, acceptable by the Python Community? If it is then should a draft 
PEP be submitted or should a PR be directly submitted to 
https://github.com/python/cpython?

I don't think this requires a new exception type. The point about BaseException being a worse choice than ModuleNotFoundError has already been made.

The stdlib curses module depends on _curses that may not be present, which is a flaw in my view, and obviously it has taken some research to find the reason. Your complaint is either against the documentation of the curses module (https://docs.python.org/3/library/curses.html#module-curses), for not telling you sooner, or against the text of the curses module itself.

The how-to (https://docs.python.org/3/howto/curses.html#curses-howto) does mention the problem and provides pointers to fix it, but incorrectly states that it is the curses module itself that will not be found, not the inner _curses. So that may sow additional confusion. I expect the reasons for this inaccuracy are in the change history.

In curses, the author could have wrapped the specific import in try-except to raise a more informative ModuleNotFoundError:

try:
    from _curses import *
except ModuleNotFoundError:
    raise ModuleNotFoundError("_curses! If only this were not a pesky Windows 
machine!")

Or something better you choose.

Either the documentation fixes or the code change would make a sensible PR, I think. Or why not addess all three? (It's surely not a PEP.)


Jeff Allen

_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/[email protected]/message/VST2TULO3ACN47LTQKRNSE2PJE4ECYRB/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to