Conversation
This comment has been minimized.
This comment has been minimized.
|
|
||
| _KeyType: TypeAlias = str | bytes | ||
| _ValueType: TypeAlias = str | bytes | ||
| _ValueType: TypeAlias = str | bytes | bytearray |
There was a problem hiding this comment.
This alias is only used in _Database.__setitem__() as far as I can see (unless the definition is imported elsewhere).
value is parsed using s#, so I think this should be ReadOnlyBuffer:
Alternatively, if we want to use the same type for all database types (which is reasonable), I think we should define _ValueType centrally and reuse it.
There was a problem hiding this comment.
It's a bit more complicated than that. The C code you point to is for dbm.ndbm. The class at issue in this file, dbm._Database, doesn't exist at runtime. We use it as the return type for dbm.open, which can return an instance of any of the database classes in the dbm package. I think the intent is that dbm._Database reflects the common interface of all three. Maybe we should use a Union return type instead?
I think for now I'll switch it to str | bytes, which are the types that all three dbm implementations support. (dbm.dumb is str | bytes | bytearray, the other two are str | ReadOnlyBuffer).
|
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
No description provided.