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

parse empy entries as empty lists so prevent exception in loops #50

Merged
merged 1 commit into from
Apr 20, 2022

Conversation

hitimr
Copy link
Contributor

@hitimr hitimr commented Jan 31, 2022

in some cases conf.yaml may contain nothing under "entries"
yaml parses these as NoneType which are not iterable. This triggers an exception in loops

For example:

func.py

def save_profile(name, profile_list, force=False):
  ...
  for section in konsave_config:
          location = konsave_config[section]["location"]
          folder = os.path.join(profile_dir, section)
          mkdir(folder)
          for entry in konsave_config[section]["entries"]:    #Throws and error
              source = os.path.join(location, entry) 
              dest = os.path.join(folder, entry)
              if os.path.exists(source):
                  if os.path.isdir(source):
                      copy(source, dest)
                  else:
                      shutil.copy(source, dest)

To resolve this we can convert all None-Entries into empty lists recursively before returning the parsed config

This should also resolve #47

@Prayag2
Copy link
Owner

Prayag2 commented Jan 31, 2022

Great! I tested it and it works. Thanks for fixing the bug. I was having a hard time figuring it out..
Please add doc strings in your function and use black formatter to format your code as mentioned in CONTRIBUTIONS.md.

@ghost
Copy link

ghost commented Feb 16, 2022

I also need this change, :)

@Prayag2
Copy link
Owner

Prayag2 commented Feb 16, 2022

Great! I tested it and it works. Thanks for fixing the bug. I was having a hard time figuring it out.. Please add doc strings in your function and use black formatter to format your code as mentioned in CONTRIBUTIONS.md.

Please reply @hitimr

@Prayag2
Copy link
Owner

Prayag2 commented Apr 20, 2022

Since, there was no reply but this fix is needed, I'll merge it. Thank you :)

@Prayag2 Prayag2 merged commit 8e20807 into Prayag2:master Apr 20, 2022
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

Successfully merging this pull request may close these issues.

Konsave: 'NoneType' object is not subscriptable
2 participants