Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DeprecationWarning: BaseException.message has been deprecated as of Python 2.6 #119

Closed
kierun opened this issue Sep 1, 2016 · 9 comments

Comments

@kierun
Copy link

kierun commented Sep 1, 2016

Using configobj (5.0.6), I tried the following and got a DeprecationWarning:

Python 2.7.5 (default, Aug 18 2016, 15:58:25)
Type "copyright", "credits" or "license" for more information.

IPython 5.0.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: from configobj import ConfigObj
   ...: from configobj import ConfigObjError
   ...:
   ...:     cfg = [str('thing  {"a": 1}')]
   ...:     c = ConfigObj(cfg)
   ...: except ConfigObjError as ex:
   ...:     print(ex.errors)
   ...:     for error in ex.errors:
   ...:         print(error.message)
   ...:
[ParseError('Invalid line (\'thing  {"a": 1}\') (matched as neither section nor keyword) at line 1.',)]
/home/yann/.virtualenvs/rprs_bootstrap/bin/ipython:7: DeprecationWarning: BaseException.message has been deprecated as of Python 2.6
  from IPython import start_ipython
Invalid line ('thing  {"a": 1}') (matched as neither section nor keyword) at line 1.

Same with plain Python:

Python 2.7.5 (default, Aug 18 2016, 15:58:25)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from configobj import ConfigObj
>>> from configobj import ConfigObjError
>>>
>>> try:
...     cfg = [str('thing  {"a": 1}')]
...     c = ConfigObj(cfg)
... except ConfigObjError as ex:
...     print(ex.errors)
...     for error in ex.errors:
...         print(error.message)
...
[ParseError('Invalid line (\'thing  {"a": 1}\') (matched as neither section nor
keyword) at line 1.',)]
Invalid line ('thing  {"a": 1}') (matched as neither section nor keyword) at line 1.

Am I doing the catching wrong somehow?

@jhermann
Copy link
Collaborator

jhermann commented Sep 1, 2016

Prefer str(ex), or even better, use it in a format (then the str is implicit). Basically you are duplicating the code in the __str__ of the exception.

@kierun
Copy link
Author

kierun commented Sep 1, 2016

That works even better for me!

Should the documentation on exceptions be updated to reflect that or is it just me being dense? ;)

@jhermann
Copy link
Collaborator

jhermann commented Sep 1, 2016

Docs can certainly be improved, PRs would help to that.

Also consider testing your code with git head, parsing errors were improved (#73).

@kierun
Copy link
Author

kierun commented Sep 1, 2016

Not sure if this merits a PR for a few lines of text but as soon as my other one is either trashed or modified, I can submit a new one. To be fair, I was a little dense: __str__ is kinda the Pythonic way to print exceptions. ^_~

@jhermann
Copy link
Collaborator

jhermann commented Sep 1, 2016

Not sure if this merits a PR for a few lines of text…

Use the embedded editor of GitHub for that and it becomes a breeze (GH basically does everything for you, including the initial fork). Try it, you'll like it.

@kierun
Copy link
Author

kierun commented Sep 1, 2016

\grins I'll give that a go tomorrow…

@kierun
Copy link
Author

kierun commented Sep 2, 2016

Done a PR. You were right, the editor is good.

@hugovk
Copy link

hugovk commented Oct 13, 2018

Can this be closed now #120 is merged?

@kierun
Copy link
Author

kierun commented Oct 15, 2018

I guess it can…

@kierun kierun closed this as completed Oct 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants