[issue16382] Better warnings exception for bad category

2014-07-11 Thread Roundup Robot

Roundup Robot added the comment:

New changeset c4a86fe52006 by Berker Peksag in branch 'default':
Issue #16382: Improve exception message of warnings.warn() for bad category.
http://hg.python.org/cpython/rev/c4a86fe52006

--
nosy: +python-dev

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16382
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16382] Better warnings exception for bad category

2014-07-11 Thread Berker Peksag

Berker Peksag added the comment:

Thanks for the patch, Phil.

--
assignee:  - berker.peksag
nosy: +r.david.murray
resolution:  - fixed
stage: patch review - resolved
status: open - closed
type: behavior - enhancement

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16382
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16382] Better warnings exception for bad category

2014-06-24 Thread Berker Peksag

Berker Peksag added the comment:

Here's a new patch addressing Ezio's Rietveld comment. I've also used 
assertRaisesRegex instead of assertRaises in tests.

--
nosy: +berker.peksag
Added file: http://bugs.python.org/file35772/issue16382_v5.diff

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16382
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16382] Better warnings exception for bad category

2014-01-23 Thread Berker Peksag

Changes by Berker Peksag berker.pek...@gmail.com:


--
versions: +Python 3.5 -Python 3.4

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16382
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16382] Better warnings exception for bad category

2013-03-04 Thread Phil Elson

Phil Elson added the comment:

Ok. I think I've done all of the actions from the reviews.

I'm not sure if I should remove the old patches or not?

Thanks,

--
Added file: http://bugs.python.org/file29304/pelson_warnings_fix_4.diff

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16382
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16382] Better warnings exception for bad category

2012-11-22 Thread Phil Elson

Changes by Phil Elson pelson@gmail.com:


Added file: http://bugs.python.org/file28072/pelson_warnings_fix_3.diff

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16382
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16382] Better warnings exception for bad category

2012-11-20 Thread Phil Elson

Changes by Phil Elson pelson@gmail.com:


Added file: http://bugs.python.org/file28053/pelson_warnings_fix_2.diff

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16382
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16382] Better warnings exception for bad category

2012-11-02 Thread Ezio Melotti

Changes by Ezio Melotti ezio.melo...@gmail.com:


--
nosy: +ezio.melotti
stage:  - patch review

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16382
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16382] Better warnings exception for bad category

2012-11-01 Thread Phil Elson

New submission from Phil Elson:

When passing an invalid Warning subclasses to the warnings.warn function, a 
bare issubclass exception is raised:


 import warnings
 warnings.warn('hello world', 'not a valid warning type')
Traceback (most recent call last):
  File stdin, line 1, in module
TypeError: issubclass() arg 1 must be a class


This exception is consistent accross both Python/_warnings.c and 
Lib/warnings.py implementations, but I feel it could be more helpful/explicit 
about the nature problem.


To test both cases I have been using the following code (python3.4):

 import test.support
 py_warnings = test.warnings = test.support.import_fresh_module('warnings', 
 blocked=['_warnings'])
 c_warnings = test.support.import_fresh_module('warnings', 
 fresh=['_warnings'])


Now:


 py_warnings.warn('hello world', '')
Traceback (most recent call last):
  File stdin, line 1, in module
  File lib/python3.4/warnings.py, line 168, in warn
assert issubclass(category, Warning)
TypeError: issubclass() arg 1 must be a class

 c_warnings.warn('hello world', '')
Traceback (most recent call last):
  File stdin, line 1, in module
TypeError: issubclass() arg 1 must be a class



Additionally, there is a difference in the denotational semantics of None 
between the c and py warnings implementation:


 py_warnings.warn('Hello world', None)
__main__:1: UserWarning: Hello world

 c_warnings.warn('Hello world', None)
Traceback (most recent call last):
  File stdin, line 1, in module
TypeError: issubclass() arg 1 must be a class


I can understand that python does not allow the concept of an optional 
positional arguments and therefore it is arguable that the signatures of the 
two functions are inevitably going to be different. I defer to someone more 
knowledgeable in Python to decide if this is a problem, and whether it should 
be made consistent.


Attached is a patch to address these two issues, with associated tests. Please 
review (n.b. I am a python developer at heart, and only dabble in C when I have 
to, so extra scrutiny on the C would be valuable to me) and I'd be happy to get 
any necessary changed applied to the patch asap.


In short, as a result of applying this patch, the following results ensue:

 py_warnings.warn('hello world', '')
Traceback (most recent call last):
  File stdin, line 1, in module
  File lib/python3.4/warnings.py, line 175, in warn
'Got {!r}'.format(Warning, category)) from None
ValueError: category must be a subclass of class 'Warning'.Got ''


 c_warnings.warn('hello world', '')
Traceback (most recent call last):
  File stdin, line 1, in module
ValueError: category must be a subclass of class 'Warning'. Got ''.
 
 c_warnings.warn('hello world', None)
__main__:1: UserWarning: hello world



Thanks!

--
components: Library (Lib)
files: pelson_warnings_fix.diff
keywords: patch
messages: 174421
nosy: pelson
priority: normal
severity: normal
status: open
title: Better warnings exception for bad category
type: behavior
versions: Python 3.4
Added file: http://bugs.python.org/file27824/pelson_warnings_fix.diff

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16382
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16382] Better warnings exception for bad category

2012-11-01 Thread Antoine Pitrou

Changes by Antoine Pitrou pit...@free.fr:


--
nosy: +brett.cannon

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16382
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com