jupyter / nbformat

Reference implementation of the Jupyter Notebook format

Home Page:http://nbformat.readthedocs.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

AttributeError: module 'warnings' has no attribute 'warning'

sbenthall opened this issue · comments

I'm getting an error when trying to import nbformat.current

$ python
Python 3.9.7 (default, Sep 10 2021, 14:59:43) 
[GCC 11.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from nbformat import current as nbformat
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/sb/projects/bigbang/bigbang-env/lib/python3.9/site-packages/nbformat/current.py", line 14, in <module>
    warnings.warning(
AttributeError: module 'warnings' has no attribute 'warning'

This is with the following version of nbformat:

>>> import nbformat
>>> nbformat.__version__
'5.3.0'

This is fixed by importing and reading it instead as:

import nbformat

with open(filename) as f:
nb = nbformat.read(f.read())

This particular problem is fixed by:

Description: fix 'warnings' module having no 'warning' but a 'warn'
Author: Julien Puydt
Forwarded: https://github.com/jupyter/nbformat/issues/267

--- nbformat.orig/nbformat/current.py
+++ nbformat/nbformat/current.py
@@ -11,7 +11,7 @@
 import re
 import warnings
 
-warnings.warning(
+warnings.warn(
     """nbformat.current is deprecated.
 
 - use nbformat for read/write/validate public API
@@ -83,7 +83,7 @@
 
 
 def _warn_format():
-    warnings.warning(
+    warnings.warn(
         """Non-JSON file support in nbformat is deprecated.
     Use nbconvert to create files of other formats."""
     )
@@ -107,13 +107,13 @@
 
 def reads_json(nbjson, **kwargs):
     """DEPRECATED, use reads"""
-    warnings.warning("reads_json is deprecated, use reads")
+    warnings.warn("reads_json is deprecated, use reads")
     return reads(nbjson)
 
 
 def writes_json(nb, **kwargs):
     """DEPRECATED, use writes"""
-    warnings.warning("writes_json is deprecated, use writes")
+    warnings.warn("writes_json is deprecated, use writes")
     return writes(nb, **kwargs)

of course I then get another failure in the test suite:

nbformat/current.py:14: in <module>
    warnings.warn(
E   UserWarning: nbformat.current is deprecated.
E   
E   - use nbformat for read/write/validate public API
E   - use nbformat.vX directly to composing notebooks of a particular version

but that will probably be another issue/patch...

Fixed by #269, working on a release today.