PySlurm / pyslurm

Python Interface to Slurm
https://pyslurm.github.io
GNU General Public License v2.0
474 stars 116 forks source link

TypeError: Expected unicode, got dict #280

Closed edoyango closed 1 year ago

edoyango commented 1 year ago

Details

Issue

PySlurm installs correctly but when I use it in my script, it errors:

$ show_cluster
Traceback (most recent call last):
  File "/stornext/Home/data/allstaff/y/yang.e/micromamba/envs/clusterinfo-venv/bin/show_cluster", line 8, in <module>
    sys.exit(main())
  File "/stornext/Home/data/allstaff/y/yang.e/micromamba/envs/clusterinfo-venv/lib/python3.6/site-packages/clusterinfo/show_cluster.py", line 18, in main
    c.get_nodes()
  File "/stornext/Home/data/allstaff/y/yang.e/micromamba/envs/clusterinfo-venv/lib/python3.6/site-packages/clusterinfo/cluster.py", line 232, in get_nodes
    partitions = pyslurm.partition().get()
  File "pyslurm/pyslurm.pyx", line 1048, in pyslurm.pyslurm.partition.get
    Part_dict['flags'] = get_partition_mode(record.flags,
  File "pyslurm/pyslurm.pyx", line 6533, in pyslurm.pyslurm.get_partition_mode
    return __get_partition_mode(flags, max_share)
TypeError: Expected unicode, got dict

The error arises for any version of Python/gcc/Cython I use.

If I change

def get_partition_mode(uint16_t flags=0, uint16_t max_share=0) -> str:

to

def get_partition_mode(uint16_t flags=0, uint16_t max_share=0) -> dict:

on line 6523, the error is resolved. The addition of -> str seems to have been introduced in https://github.com/PySlurm/pyslurm/commit/3b8932539361a1e72445d2429026af10b9bd8738

tazend commented 1 year ago

Hi,

thanks for reporting. Well, it seems to be the case that Cython does type checking on the return value when return type annotations are used. I will make the fix later today.

tazend commented 1 year ago

Hi again,

it should be fixed now in the main branch

edoyango commented 1 year ago

@tazend thanks for the speedy resolution!