tail-f-systems / JNC

JNC (Java NETCONF Client) is the name of a Java library for communicating with NETCONF agents, and a plugin for pyang (http://code.google.com/p/pyang/) to generate Java classes from YANG models, to be used by the JNC library.
Other
77 stars 87 forks source link

Getting unhashable type: 'JavaMethod' when pyang 2.5.2 is using python3 #93

Closed pramodak closed 1 year ago

pramodak commented 2 years ago

We are moving to python3 (since python2 is deprecated) and we see an issue while generating java classes with the below command (which was working with python2 + pyang 2.5.2)

/tmp/pyang-2.5.2/bin/pyang -f jnc --jnc-no-pkginfo --jnc-output /tmp/out/ <yang>

Stack trace:

Traceback (most recent call last):
  File "/tmp/pyang-2.5.2/bin/pyang", line 5, in <module>
    __import__('pkg_resources').run_script('pyang==2.5.2', 'pyang')
  File "/opt/rh/rh-python36/root/usr/lib/python3.6/site-packages/pkg_resources/__init__.py", line 748, in run_script
    self.require(requires)[0].run_script(script_name, ns)
  File "/opt/rh/rh-python36/root/usr/lib/python3.6/site-packages/pkg_resources/__init__.py", line 1517, in run_script
    exec(code, namespace, namespace)
  File "/tmp/pyang-2.5.2/lib/python3.6/site-packages/pyang-2.5.2-py3.6.egg/EGG-INFO/scripts/pyang", line 545, in <module>
    run()
  File "/tmp/pyang-2.5.2/lib/python3.6/site-packages/pyang-2.5.2-py3.6.egg/EGG-INFO/scripts/pyang", line 514, in run
    emit_obj.emit(ctx, modules, fd)
  File "/tmp/pyang-2.5.2/lib/python3.6/site-packages/pyang-2.5.2-py3.6.egg/pyang/plugins/jnc.py", line 224, in emit
    self.generate_from(module)
  File "/tmp/pyang-2.5.2/lib/python3.6/site-packages/pyang-2.5.2-py3.6.egg/pyang/plugins/jnc.py", line 261, in generate_from
    generator.generate()
  File "/tmp/pyang-2.5.2/lib/python3.6/site-packages/pyang-2.5.2-py3.6.egg/pyang/plugins/jnc.py", line 1007, in generate
    self.generate_classes()
  File "/tmp/pyang-2.5.2/lib/python3.6/site-packages/pyang-2.5.2-py3.6.egg/pyang/plugins/jnc.py", line 1080, in generate_classes
    java_class.add_constructor(constructor)
  File "/tmp/pyang-2.5.2/lib/python3.6/site-packages/pyang-2.5.2-py3.6.egg/pyang/plugins/jnc.py", line 1461, in add_constructor
    self.constructors.add(constructor)
  File "/tmp/pyang-2.5.2/lib/python3.6/site-packages/pyang-2.5.2-py3.6.egg/pyang/plugins/jnc.py", line 3010, in add
    if item not in self:
  File "/tmp/pyang-2.5.2/lib/python3.6/site-packages/pyang-2.5.2-py3.6.egg/pyang/plugins/jnc.py", line 3006, in __contains__
    return item in self.map
TypeError: unhashable type: 'JavaMethod'

If there is a workaround could anyone help? Do we have to define the __hash__() method for JavaMethod class of jnc module? - Is there any reference?

jomiklos commented 1 year ago

This has been possibly fixed with some of the "revival" updates (merged to master with 5e0dccc604c454ece1b6c0e794733fcec69d892a).

I can now successfully run:

user@machine:~/JNC/examples/0-intro$ python3 --version
Python 3.8.10
user@machine:~/JNC/examples/0-intro$ pyang --version
pyang 2.5.3
user@machine:~/JNC/examples/0-intro$ head -3 `which pyang`
#!/usr/bin/python3
user@machine:~/JNC/examples/0-intro$
user@machine:~/JNC/examples/0-intro$ pyang -f jnc --jnc-no-pkginfo --jnc-output out/src ./hosts.yang  --path ~/confd/confd-7.4/src/confd/yang/
user@machine:~/JNC/examples/0-intro$ tree out/ | head -8
out/
└── src
    ├── hosts
    │   ├── Conny.java
    │   ├── Hosts.java
    │   ├── Rej.java
    │   ├── Simple.java
    │   ├── Simple.schema