<p>改变的主要原因似乎是为了实现一致性,并为mypy键入,以便<code>int</code>可以是<code>float</code>的子类型</p>
<blockquote>
<p>msg313780 - (view) Author: Raymond Hettinger (rhettinger) * (Python
committer) Date: 2018-03-13 21:25</p>
<p>Goal: make int() more interoperable with float by making a
float/Decimal method also available on ints. This will let mypy treat
ints as a subtype of floats.</p>
<p>See:
<a href="https://mail.python.org/pipermail/python-dev/2018-March/152384.html" rel="nofollow noreferrer">https://mail.python.org/pipermail/python-dev/2018-March/152384.html</a></p>
<p>Open question: Is this also desired for fractions.Fraction and
numbers.Rational?</p>
</blockquote>
<p>深入到pipermail中,它似乎有助于通过分解等方式更改类型的域:</p>
<blockquote>
<p>[Python-Dev] Symmetry arguments for API expansion Guido van Rossum
guido at python.org Tue Mar 13 15:07:15 EDT 2018</p>
<pre><code>Previous message (by thread): [Python-Dev] Symmetry arguments for API expansion
Next message (by thread): [Python-Dev] Symmetry arguments for API expansion
Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
</code></pre>
<p>OK, please make it so.</p>
<p>On Tue, Mar 13, 2018 at 11:39 AM, Raymond Hettinger <
raymond.hettinger at gmail.com> wrote:</p>
<blockquote>
<blockquote>
<p>On Mar 13, 2018, at 10:43 AM, Guido van Rossum wrote:</p>
<p>So let's make as_integer_ratio() the standard protocol for "how to make
a Fraction out of a number that doesn't implement numbers.Rational". We
already have two examples of this (float and Decimal) and perhaps numpy or
the sometimes proposed fixed-width decimal type can benefit from it too. If
this means we should add it to int, that's fine with me.</p>
</blockquote>
<p>我希望看到这一结果</p>
<p>签名x.as_integer_ratio()->;(int,int)工作起来很愉快
具有输出很容易解释,分母也不受约束
二或十的幂。由于Python int是精确且无限制的,因此
不必担心范围或舍入问题</p>
<p>相比之下,math.frexp(float)——>;(float,int)有点痛苦,因为
仍然将您留在浮动域中,而不是让您分解
到更基本的类型。很高兴能有办法沿着链条向下移动
从…起ℚ, ℝ, 或ℂ 更基本的ℤ (当然,这只是因为
浮点数和复数的实现方式排除了精确的
非理性)</p>
<p>雷蒙德</p>
</blockquote>
</blockquote>
<p>见:</p>
<ul>
<li><a href="https://bugs.python.org/issue33073" rel="nofollow noreferrer">https://bugs.python.org/issue33073</a></li>
</ul>