Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: the element must be a dictionary or a list but is of type '<class 'str'>' #28

Open
hagfelsh opened this issue Jun 30, 2021 · 0 comments

Comments

@hagfelsh
Copy link

So this is quite a puzzle. I've followed the code through scalpl.py's setdefault() function and I'm still not sure why this is happening.

The short of it is "why is this happening and what am I missing"...

I hope this reproduces for you as easily as it does for me!

Some environment details in case that's relevant somehow:

  • Linux Mint 20
  • Pycharm Pro 2021.1.2 (latest)
  • venv python version 3.8.10
  • scalpl version 0.4.2

Here's the traceback:

I've also attached a screenshot of the pycharm debug window describing exception.


Traceback (most recent call last):
  File "/home/keiser/PycharmProjects/vmagic_web/venv/lib/python3.8/site-packages/scalpl/scalpl.py", line 252, in setdefault
    return item[last_key]
TypeError: string indices must be integers

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/keiser/.config/JetBrains/PyCharm2021.1/scratches/scalpl_problem.py", line 62, in parsevmx
    vmx_dict.setdefault(keystr, value)
  File "/home/keiser/PycharmProjects/vmagic_web/venv/lib/python3.8/site-packages/scalpl/scalpl.py", line 259, in setdefault
    raise type_error(last_key, path, item)
  File "/home/keiser/PycharmProjects/vmagic_web/venv/lib/python3.8/site-packages/scalpl/scalpl.py", line 37, in type_error
    raise TypeError(
TypeError: Cannot access key 'amd' in path 'cpuid.80000001.eax.amd': the element must be a dictionary or a list but is of type '<class 'str'>'.
python-BaseException

Here's the script that's generating this problem.

The idea is to parse the source file (pasted below) and return a dictionary of its contents.
https://pastebin.com/Qm94aWLA

Here's the source file the script is designed to work against:

It's worth noting that this problem doesn't happen on every file like this. Many of them work just fine.
Problem example:
https://pastebin.com/fLSrcAyA

Working example:
https://pastebin.com/E9m4NS27

I created two vimdiff html files to compare these two. One examines the files as-is and the other examines a sorted version of them. In order to upload them to github, I've appended .txt to the filename--just trim that off and you can view them in a browser easily enough. Or diff them with your own tools of course!

sorted_vmx_differences.html.txt
vmx_differences_unsorted.html.txt

The most significant difference between working and non-working appears to involve this block of text. Perhaps something here is too dirty to handle as-is? I tried replacing the '-' characters in right side of the = with 'X' but that made no difference.

cpuid.80000001.eax = "--------------------------------"
cpuid.80000001.ebx = "--------------------------------"
cpuid.80000001.ecx = "--------------------------------"
cpuid.80000001.edx = "-----------H--------------------"
cpuid.80000001.eax.amd = "--------------------------------"
cpuid.80000001.ebx.amd = "--------------------------------"
cpuid.80000001.ecx.amd = "--------------------------------"
cpuid.80000001.edx.amd = "-----------H--------------------"

By the way--scalpl is a delight to use, thank you for sharing it. I use it all the time :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant