Skip to content

RuRo/new-python-warnings-poc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Proof of Concept implementation for new Warning formatting

See, this discuss thread for context. Based on CPython warnings.py@d8f40ead.

Keep in mind, that the current implementation:

  • Assumes Python 3.11 or newer. (Uses the new co_positions() method)

  • Is written in pure Python. (The C _warning extension loading is disabled)

  • Is not well tested. (I haven't checked any warnings APIs apart from warnings.warn)

  • Is currently not backwards compatible. (I've added some new fields and parameters, which probably breaks monkey-patching)

You can see an example comparison between old and new warnings by running ./compare_warnings.sh or ./compare_warnings_in_docker.sh if you don't have Python 3.11 installed locally.

Examples

Old Warnings

/long/path/to/code/that/may/end/up/wrapping/example.py:27: UserWarning: This is a regular warning.
  warnings.warn("This is a regular warning.")
/long/path/to/code/that/may/end/up/wrapping/example.py:28: DeprecationWarning: old_baz is deprecated in version X, use new_baz instead.
  bar(old_baz() + 1)
/long/path/to/code/that/may/end/up/wrapping/example.py:19: VeryImportantWarning: This is a very important warning, you need to fix it!
  warnings.warn(

New Warnings

File "/long/path/to/code/that/may/end/up/wrapping/example.py", line 27, in foo
  UserWarning: This is a regular warning.
File "/long/path/to/code/that/may/end/up/wrapping/example.py", line 28, in foo
  bar(old_baz() + 1)
      ^^^^^^^^^
  DeprecationWarning: old_baz is deprecated in version X, use new_baz instead.
File "/long/path/to/code/that/may/end/up/wrapping/example.py", line 19, in bar
  VeryImportantWarning: This is a very important warning, you need to fix it!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published