[Python-Dev] NoneType(None) raises exception
python at mrabarnett.plus.com
Fri Apr 26 01:56:46 CEST 2013
On 26/04/2013 00:09, Ethan Furman wrote:
> We just fixed NoneType() to return None instead of raising an exception.
> Another use-case for calling NoneType is working with ORMs:
> result = 
> for field in row:
> type = get_type(field) # returns int, bool, str, NoneType, ...
> if field is None, the resulting call is NoneType(None), and since NoneType doesn't take any parameters we get an exception.
> Is it worth filing a bug to have NoneType accept one optional argument, which defaults to None, and must be None, else
> raise an exception?
> Or should it be:
> class NoneType:
> def __new__(cls, *args, **kws):
> return None
> Which is basically what my 2.x none() helper function does...
On the one hand, NoneType(None) seems a strange thing to do.
On the other hand:
type(value)(value) == value
would return True for the built-in types (will certain exceptions, such
as when value is float("NaN")).
Let's ask the Zen:
Special cases aren't special enough to break the rules.
Although practicality beats purity.
More information about the Python-Dev