Closed rnikiforova closed 3 years ago
The problem with anything implemented as a C function is that for where they expect to deal with builtin type they will often have explicit checks for the exact type (not even isinstance() equivalent) and nothing else will work. There isn't a way around it.
Why are you inheriting from builtin types anyway?
For primitive literal types (eg., string, integers, floats) inheriting them from them isn't necessarily a good idea.
There isn't a way around it.
:-(
Why are you inheriting from builtin types anyway?
I didn't plan to, I included it for comparison purposes. However, I'm now considering it since the type (either string or proxy) is not known in advance and they should be interchangeable.
Going to close out this issue as there isn't really a solution for wrapping basic types in Python. For some things it may be possible, but not for many other things.
I'm experiencing some issues wrapping base types such as str. For example, the
str.join()
fails with "expected str instance" which doesn't happen whenstr
is inherited directly.Example
Produces:
Meanwhile, the concatenation works as expected:
Versions:
I've experienced the same issue with the
re
module ('expected string or bytes-like object"). I've also experienced it when wrapping int. For example,datetime.timedelta
fails with "TypeError: unsupported type for timedelta days component" when using a proxy object.Workaround
Currently, the workaround is to convert it to the appropriate type:
However, it would be great if this wasn't needed as other developers on the project should be able to use the proxy without knowing it's a proxy. We use the proxy to store some information about the underlying data.