Repository: tomerfiliba-org/rpyc

Issue #355: Class netrefs return wrong __class__ value
Created: 2019-10-18T23:50:01Z
As of release 4.1, it seems that netrefs that represent classes are returning incorrect values for the __class__ attribute.  type() calls are also returning similarly incorrect results.
# rpyc v4.1.2 (surprising/incorrect behavior):
>>> import rpyc
>>> conn = rpyc.classic.connect("localhost")
>>> conn.modules.__builtin__.float.__class__
<type 'float'>
>>> type(conn.modules.__builtin__.float)
<netref class 'rpyc.core.netref.__builtin__.float'>


# rpyc v3.3.0 (expected behavior):
>>> import rpyc
>>> conn = rpyc.classic.connect("localhost")
>>> conn.modules.__builtin__.float.__class__
<type 'type'>
>>> type(conn.modules.__builtin__.float)
<netref class '__builtin__.type'>


# just python, no rpyc (consistent with rpyc v3.3.0 behavior)
>>> float.__class__
<type 'type'>
>>> type(float)
<type 'type'>
We encountered this change in behavior when we attempted to upgrade from 3.3.0 to 4.1.2 and it caused a number of problems in code that was depending on the type handling to work as expected.
To complicate matters, it looks like the fix for #339 included a change to the implementation of BaseNetref.__instancecheck__ that is now relying on this incorrect behavior.  The last line of __instancecheck__ is now calling isinstance(other, self.__class__) rather than isinstance(other, self).  self represents the correct class to check, but self.__class__ is working because self.__class__ is incorrectly returning self (or the local value of self, depending on whether the class is a builtin).
Environment

rpyc version: 4.1.2
python version: 2.7.13
operating system: linux

Duplicate issue #390: Can't reproduce examples from netref docu
Created: 2020-07-07T08:17:51Z
Hi there,
When running the examples from netref tutorial (https://rpyc.readthedocs.io/en/latest/tutorial/tut2.html) I don't get the same results.
Could you please clarify the expected behaviour?
If you are interested I could add some doctests to the sphinx documentation. I just don't know the proper way to run them yet.
Environment

rpyc version: 4.1.5
python version: 3.6.8
operating system: Ubuntu 18.04

Minimal example
Server:
from rpyc.utils.zerodeploy import DeployedServer
from plumbum import SshMachine

machine = SshMachine("127.0.0.1")
server = DeployedServer(machine)
conn = server.classic_connect()
print(f"type(conn.modules.sys): {type(conn.modules.sys)}, in docu: <netref class 'builtins.module'>")
print(f"type(conn.modules.sys.path): {type(conn.modules.sys.path)}, in docu: <netref class 'builtins.list'>")
print(f"type(conn.modules.os.path.abspath): {type(conn.modules.os.path.abspath)}, in docu: <netref class 'builtins.function'>")

print(f"isinstance(conn.modules.sys.path, list): {isinstance(conn.modules.sys.path, list)}, in docu: True")

import inspect
print(f"inspect.isbuiltin(conn.modules.os.listdir): {inspect.isbuiltin(conn.modules.os.listdir)}, in docu: True")
print(f"inspect.isbuiltin(conn.modules.os.path.abspath): {inspect.isfunction(conn.modules.os.path.abspath)}, in docu: True")
print(f"inspect.ismethod(conn.modules.os.path.abspath): {inspect.ismethod(conn.modules.os.path.abspath)}, in docu: False")
print(f"inspect.ismethod(conn.modules.sys.stdout.write): {inspect.ismethod(conn.modules.sys.stdout.write)}, in docu: True")
Results:
type(conn.modules.sys): <netref class 'rpyc.core.netref.sys'>, in docu: <netref class 'builtins.module'>
type(conn.modules.sys.path): <netref class 'rpyc.core.netref.type'>, in docu: <netref class 'builtins.list'>
type(conn.modules.os.path.abspath): <netref class 'rpyc.core.netref.builtins.function'>, in docu: <netref class 'builtins.function'>
isinstance(conn.modules.sys.path, list): True, in docu: True
inspect.isbuiltin(conn.modules.os.listdir): False, in docu: True
inspect.isbuiltin(conn.modules.os.path.abspath): False, in docu: True
inspect.ismethod(conn.modules.os.path.abspath): False, in docu: False
inspect.ismethod(conn.modules.sys.stdout.write): False, in docu: True

Closing comment (2021-03-22T04:33:49Z): Duplicate of #355
Thank you for reporting to help provide more test cases