rimvaliulin / isorted

isort integration for Sublime Text
GNU General Public License v3.0
11 stars 2 forks source link

Doesn't work without an open project #11

Open Marrin opened 6 months ago

Marrin commented 6 months ago

If sorting is invoked without an open project, the following exception is raised:

Traceback (most recent call last):
  File "/home/bj/src/sublime_text/Lib/python33/sublime_plugin.py", line 1499, in run_
    return self.run(edit)
  File "/home/bj/.config/sublime-text-3/Installed Packages/isorted.sublime-package/isorted.py", line 33, in run
  File "/home/bj/.config/sublime-text-3/Installed Packages/isorted.sublime-package/isorted.py", line 62, in command_line
  File "/home/bj/.config/sublime-text-3/Installed Packages/isorted.sublime-package/isorted.py", line 114, in settings
AttributeError: 'NoneType' object has no attribute 'get'

Line 114 reads:

        for name, value in self.view.window().project_data().get("settings", {}).items():

I think this should be guarded against project_data() returning None instead of a dictionary. Something like this:

        project_data = self.view.window().project_data()
        if project_data:
            for name, value in project_data.get("settings", {}).items():