Skip to content

Commit fe29b8a

Browse files
author
暮晨
committed
EX.Subclass relationships
1 parent eaad9fb commit fe29b8a

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

README.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ So, here we go...
4747
- [> The disappearing variable from outer scope/消失的外部变量](#-the-disappearing-variable-from-outer-scope消失的外部变量)
4848
- [> When True is actually False/真亦假](#-when-true-is-actually-false真亦假)
4949
- [> From filled to None in one instruction.../从有到无...](#-from-filled-to-none-in-one-instruction从有到无)
50-
- [> Subclass relationships *](#-subclass-relationships-)
50+
- [> Subclass relationships/子类关系 *](#-subclass-relationships子类关系-)
5151
- [> The mysterious key type conversion *](#-the-mysterious-key-type-conversion-)
5252
- [> Let's see if you can guess this?](#-lets-see-if-you-can-guess-this)
5353
- [Section: Appearances are deceptive!](#section-appearances-are-deceptive)
@@ -1091,7 +1091,7 @@ None
10911091
10921092
---
10931093
1094-
### > Subclass relationships *
1094+
### > Subclass relationships/子类关系 *
10951095
10961096
**Output:**
10971097
```py
@@ -1104,14 +1104,14 @@ True
11041104
False
11051105
```
11061106
1107-
The Subclass relationships were expected to be transitive, right? (i.e., if `A` is a subclass of `B`, and `B` is a subclass of `C`, the `A` _should_ a subclass of `C`)
1107+
子类关系应该是可传递的, 对吧? (即, 如果 `A` `B` 的子类, `B` `C` 的子类, 那么 `A` _应该_ 是 `C` 的子类.)
11081108
1109-
#### 💡 Explanation:
1109+
#### 💡 说明:
11101110
1111-
* Subclass relationships are not necessarily transitive in Python. Anyone is allowed to define their own, arbitrary `__subclasscheck__` in a metaclass.
1112-
* When `issubclass(cls, Hashable)` is called, it simply looks for non-Falsey "`__hash__`" method in `cls` or anything it inherits from.
1113-
* Since `object` is hashable, but `list` is non-hashable, it breaks the transitivity relation.
1114-
* More detailed explanation can be found [here](https://www.naftaliharris.com/blog/python-subclass-intransitivity/).
1111+
* Python 中的子类关系并不必须是传递的. 任何人都可以在元类中随意定义 `__subclasscheck__`.
1112+
* `issubclass(cls, Hashable)` 被调用时, 它只是在 `cls` 中寻找 "`__hash__`" 方法或继承自"`__hash__`"的方法.
1113+
* 由于 `object` is 可散列的(hashable), 但是 `list` 是不可散列的, 所以它打破了这种传递关系.
1114+
* 在[这里](https://www.naftaliharris.com/blog/python-subclass-intransitivity/)可以找到更详细的解释.
11151115
11161116
---
11171117

0 commit comments

Comments
 (0)