classification
Title: Verbose/confusing default format on warnings
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.10
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Mithil, steven.daprano, terry.reedy
Priority: normal Keywords:

Created on 2020-10-18 22:15 by Mithil, last changed 2020-10-23 19:52 by terry.reedy.

Files
File name Uploaded Description Edit
warntest.py steven.daprano, 2020-10-18 22:32
Messages (5)
msg378906 - (view) Author: Mithil (Mithil) Date: 2020-10-18 22:15
The default format prints a lot of details like filename, line number, and the source code on that line. A particular case where the warn message is written on the next line like -
warn(
   "Message here")
Will only print warn( as the source code and not the entire block.
My concern is, can this formatting be less detailed by default. Or, can this format be freely changed in a project A without worrying about affecting the global usage in any other project B that imports it.
Or at the very least, can this be made to print the entire block of code and not just the one line, because that makes it very confusing for the user.

More takes on the issue here - https://github.com/PyCQA/isort/issues/1568
msg378908 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2020-10-18 22:32
3.9 and older are all in feature freeze, so no changes in behaviour will be considered for them.

I'm afraid I cannot replicate the behaviour you describe. When I try, the full warning message is correctly displayed. See the attached file.

Importing it from the interactive interpreter gives:

    >>> import warntest
    /home/steve/warntest.py:5: UserWarning: Danger danger danger Will Robinson!!!
      "Danger danger danger Will Robinson!!!"


and running it from the commandline:


$ python3 ~/warntest.py 
/home/steve/warntest.py:5: UserWarning: Danger danger danger Will Robinson!!!
  "Danger danger danger Will Robinson!!!"


Can you provide a minimal working example of the issue?
msg378910 - (view) Author: Mithil (Mithil) Date: 2020-10-18 22:52
I ran the file that you linked and this is what it printed.

C:\Users\mithi\p\test\file.py:3: UserWarning: Danger danger danger Will Robinson!!!
  warnings.warn(

As you see, the warnings.warn( line is not desirable.
More details about my machine -
Windows 10
python 3.9.0

I have also tried running this with Python 3.10.0a1. Same result.
msg378912 - (view) Author: Mithil (Mithil) Date: 2020-10-18 23:02
I also ran this on Fedora 32, python 3.8.6 and still got the same result.
msg379472 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2020-10-23 19:52
An application *can* change warnings.  See lib/idlelib/run for an example.  Library code should not make changes as they will be global or overwritten.  A project that is both can restrict the changes to when run as main module.
History
Date User Action Args
2020-10-23 19:52:53terry.reedysetnosy: + terry.reedy
messages: + msg379472
2020-10-18 23:02:43Mithilsetmessages: + msg378912
2020-10-18 22:52:21Mithilsetmessages: + msg378910
2020-10-18 22:32:05steven.dapranosetfiles: + warntest.py
versions: - Python 3.6, Python 3.7, Python 3.8, Python 3.9
nosy: + steven.daprano

messages: + msg378908
2020-10-18 22:15:40Mithilcreate