为什么sqlite3还是用__conform__?
Why does sqlite3 still use __conform__?
我注意到 sqlite3
-library 仍然使用 __conform__
- 方法来调整对象以在数据库中存储。
Then you need to give your class a method __conform__(self, protocol)
which must return the converted value.
这似乎遵循PEP 246,它指定了__conform__
-方法,但已被拒绝;
I'm rejecting this PEP. Something much better is about to happen; it's too early to say exactly what, but it's not going to resemble the proposal in this PEP too closely so it's better to start a new PEP. GvR.
^ Rejection notice of PEP 246 ^
现在,官方 Python 库怎么会实现 a standard that has been defined in a suggestion that has explicitly been rejected?
PEP 246 建议使用特定名称实现特定设计模式(测试传入对象是否遵守给定协议)。该提案如果被接受,将为 Python 语言添加一个新的特殊方法 (__conform__
),以及一个新的 built-in 函数 (adapt
)。
PEP 的决定只是拒绝了标准化。它不禁止任何 Python 包设计者在他们的代码内部创建和使用这样的 pattern/naming 约定。这类似于 sqlite3 开发人员将 Cursor
方法命名为 fetchone()
而不是 fetchnext()
的自由。在合理和实用的范围内,他们可以 name/design 随心所欲地使用他们的软件包组件。
更新 - according to Eric Snow,关于承诺即将到来的 'something much better':
At the time it referred to generic functions (a la PEP 3124: Overloading, Generic Functions, Interfaces, and Adaptation). However, ultimately it was Abstract Base Classes (PEP 3119) that slid into this space.
我注意到 sqlite3
-library 仍然使用 __conform__
- 方法来调整对象以在数据库中存储。
Then you need to give your class a method
__conform__(self, protocol)
which must return the converted value.
这似乎遵循PEP 246,它指定了__conform__
-方法,但已被拒绝;
I'm rejecting this PEP. Something much better is about to happen; it's too early to say exactly what, but it's not going to resemble the proposal in this PEP too closely so it's better to start a new PEP. GvR.
^ Rejection notice of PEP 246 ^
现在,官方 Python 库怎么会实现 a standard that has been defined in a suggestion that has explicitly been rejected?
PEP 246 建议使用特定名称实现特定设计模式(测试传入对象是否遵守给定协议)。该提案如果被接受,将为 Python 语言添加一个新的特殊方法 (__conform__
),以及一个新的 built-in 函数 (adapt
)。
PEP 的决定只是拒绝了标准化。它不禁止任何 Python 包设计者在他们的代码内部创建和使用这样的 pattern/naming 约定。这类似于 sqlite3 开发人员将 Cursor
方法命名为 fetchone()
而不是 fetchnext()
的自由。在合理和实用的范围内,他们可以 name/design 随心所欲地使用他们的软件包组件。
更新 - according to Eric Snow,关于承诺即将到来的 'something much better':
At the time it referred to generic functions (a la PEP 3124: Overloading, Generic Functions, Interfaces, and Adaptation). However, ultimately it was Abstract Base Classes (PEP 3119) that slid into this space.