<i id='nquvf'><tr id='nquvf'><dt id='nquvf'><q id='nquvf'><span id='nquvf'><b id='nquvf'><form id='nquvf'><ins id='nquvf'></ins><ul id='nquvf'></ul><sub id='nquvf'></sub></form><legend id='nquvf'></legend><bdo id='nquvf'><pre id='nquvf'><center id='nquvf'></center></pre></bdo></b><th id='nquvf'></th></span></q></dt></tr></i><div id='nquvf'><tfoot id='nquvf'></tfoot><dl id='nquvf'><fieldset id='nquvf'></fieldset></dl></div>
  • <tfoot id='nquvf'></tfoot>

      <small id='nquvf'></small><noframes id='nquvf'>

      • <bdo id='nquvf'></bdo><ul id='nquvf'></ul>
    1. <legend id='nquvf'><style id='nquvf'><dir id='nquvf'><q id='nquvf'></q></dir></style></legend>
      1. 为什么我不能在 Python 中扩展 bool?

        时间:2023-09-01
        <tfoot id='eGfex'></tfoot>

                  <tbody id='eGfex'></tbody>
              1. <legend id='eGfex'><style id='eGfex'><dir id='eGfex'><q id='eGfex'></q></dir></style></legend>
                  <bdo id='eGfex'></bdo><ul id='eGfex'></ul>
                  <i id='eGfex'><tr id='eGfex'><dt id='eGfex'><q id='eGfex'><span id='eGfex'><b id='eGfex'><form id='eGfex'><ins id='eGfex'></ins><ul id='eGfex'></ul><sub id='eGfex'></sub></form><legend id='eGfex'></legend><bdo id='eGfex'><pre id='eGfex'><center id='eGfex'></center></pre></bdo></b><th id='eGfex'></th></span></q></dt></tr></i><div id='eGfex'><tfoot id='eGfex'></tfoot><dl id='eGfex'><fieldset id='eGfex'></fieldset></dl></div>

                  <small id='eGfex'></small><noframes id='eGfex'>

                • 本文介绍了为什么我不能在 Python 中扩展 bool?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  >>> class BOOL(bool):
                  ...     print "why?"
                  ... 
                  why?
                  Traceback (most recent call last):
                    File "<stdin>", line 1, in <module>
                  TypeError: Error when calling the metaclass bases
                      type 'bool' is not an acceptable base type
                  

                  我认为 Python 信任程序员.

                  推荐答案

                  Guido 的看法:

                  我最后想到了这个晚上,并意识到你不应该完全可以继承 bool !一个子类只有在它有用时才有用有实例,但仅仅是存在bool 子类的实例会打破 True 的不变量和 False 是唯一的实例布尔!(C 的子类的一个实例也是 C 的一个实例.)我认为重要的是不要提供后门创建额外的布尔实例,所以我认为 bool 不应该可以子类化.

                  I thought about this last night, and realized that you shouldn't be allowed to subclass bool at all! A subclass would only be useful when it has instances, but the mere existance of an instance of a subclass of bool would break the invariant that True and False are the only instances of bool! (An instance of a subclass of C is also an instance of C.) I think it's important not to provide a backdoor to create additional bool instances, so I think bool should not be subclassable.

                  参考:http://mail.python.org/pipermail/python-dev/2002-March/020822.html

                  这篇关于为什么我不能在 Python 中扩展 bool?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:根据 Python 中的日期范围检查日期 下一篇:为什么 bool(xml.etree.ElementTree.Element) 评估为 False?

                  相关文章

                      • <bdo id='5IjAE'></bdo><ul id='5IjAE'></ul>

                      <small id='5IjAE'></small><noframes id='5IjAE'>

                      <legend id='5IjAE'><style id='5IjAE'><dir id='5IjAE'><q id='5IjAE'></q></dir></style></legend>
                      <tfoot id='5IjAE'></tfoot>
                      <i id='5IjAE'><tr id='5IjAE'><dt id='5IjAE'><q id='5IjAE'><span id='5IjAE'><b id='5IjAE'><form id='5IjAE'><ins id='5IjAE'></ins><ul id='5IjAE'></ul><sub id='5IjAE'></sub></form><legend id='5IjAE'></legend><bdo id='5IjAE'><pre id='5IjAE'><center id='5IjAE'></center></pre></bdo></b><th id='5IjAE'></th></span></q></dt></tr></i><div id='5IjAE'><tfoot id='5IjAE'></tfoot><dl id='5IjAE'><fieldset id='5IjAE'></fieldset></dl></div>