Open KOLANICH opened 5 years ago
Oooof ... looks like python2 os.stat will raise TypeError: coercing to Unicode: need string or buffer, Proxy found
while on python3 you get a TypeError: 'str' object cannot be interpreted as an integer
.
It would look like it fails at the argument parsing.
The problem is that the proxies (cext, simple and slots) all implement __index__
and it looks like stat tries to parse it as a fd (by converting to a number through __index__()
).
Something like this would work with the pure python implementations but it's destructive you see ...
import os
from lazy_object_proxy.slots import Proxy
del Proxy.__index__ # DESTRUCTIVE
class PathProxy(Proxy):
def __fspath__(self):
return str(self)
os.stat(PathProxy(lambda: '.'))
Thank you for the info. Can it be solved by
Proxy
to use that type on order to determine the methods (and type) of the result prior actual calling the callable?Annotations wouldn't help at all.
os.stat's checks basically do this:
__index__
then convert it to int using that__fspath__
method use that to get the stringPython is pretty broken with regard to capability checking (iow: checking if an object can do something or has a certain special method). While you can have a descriptor as a special method, and make it raise AttributeError most of the python code written in C will happily only check the existence of a slot for special method and forget about that silly descriptor stuff.
FYI v1.5.0 adds support for __fspath__
. Perhaps this is no longer a problem on latest Python?
Will try, thank you for getting me know. Though I am not sure if it will work for the versions of python not checking __fspath__
(i.e. 3.4 that is the latest version supporting Win XP).