Movatterモバイル変換


[0]ホーム

URL:


homepage

Message265191

This issue trackerhas been migrated toGitHub, and is currentlyread-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Authorserhiy.storchaka
Recipientsmark.dickinson, serhiy.storchaka
Date2016-05-09.13:46:32
SpamBayes Score-1.0
Marked as misclassifiedYes
Message-id<1462801593.23.0.789372695786.issue26983@psf.upfronthosting.co.za>
In-reply-to
Content
The float constructor can return an instance of float subclass.>>> class FloatSubclass(float):...     pass... >>> class BadFloat:...     def __float__(self):...         return FloatSubclass(1.2)... >>> type(float(BadFloat()))<class '__main__.FloatSubclass'>Comparing with other types, complex() always returns complex:>>> class ComplexSubclass(complex):...     pass... >>> class BadComplex:...     def __complex__(self):...         return ComplexSubclass(1.2, 3.4)... >>> type(complex(BadComplex()))<class 'complex'>And int() can return an instance of int subclass, but this behavior is deprecated:>>> class BadInt:...     def __int__(self):...         return True... >>> int(BadInt())__main__:1: DeprecationWarning: __int__ returned non-int (type bool).  The ability to return an instance of a strict subclass of int is deprecated, and may be removed in a future version of Python.TrueMay be we should either deprecate __float__ returning non-float (as for int), or convert the result to exact float (as for complex).The constructor of float subclass always returns an instance of correct type.>>> class FloatSubclass2(float):...     pass... >>> type(FloatSubclass2(BadFloat()))<class '__main__.FloatSubclass2'>
History
DateUserActionArgs
2016-05-09 13:46:33serhiy.storchakasetrecipients: +serhiy.storchaka,mark.dickinson
2016-05-09 13:46:33serhiy.storchakasetmessageid: <1462801593.23.0.789372695786.issue26983@psf.upfronthosting.co.za>
2016-05-09 13:46:32serhiy.storchakalinkissue26983 messages
2016-05-09 13:46:32serhiy.storchakacreate
Supported byThe Python Software Foundation,
Powered byRoundup
Copyright © 1990-2022,Python Software Foundation
Legal Statements

[8]ページ先頭

©2009-2026 Movatter.jp