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

AttributeError: 'NoneType' object has no attribute 'views' #43

Open
evandrocoan opened this issue Oct 13, 2017 · 1 comment
Open

AttributeError: 'NoneType' object has no attribute 'views' #43

evandrocoan opened this issue Oct 13, 2017 · 1 comment

Comments

@evandrocoan
Copy link

evandrocoan commented Oct 13, 2017

This showed up when Sublime Text started:

Traceback (most recent call last):
  File "D:\SublimeText\Data\Packages\ANSIescape\ansi.py", line 237, in check_left_ansi
    if not self._is_view_valid(view):
  File "D:\SublimeText\Data\Packages\ANSIescape\ansi.py", line 271, in _is_view_valid
    if view not in view.window().views():
AttributeError: 'NoneType' object has no attribute 'views'

This seems to coincides with the Overrides Reports package report.

This are the lines:

File: Data/Packages/ANSIescape/ansi.py
266:     def _is_view_valid(self, view):
267:         if view.window() is None:
268:             return False
269:         if view.window() not in sublime.windows():
270:             return False
271:         if view not in view.window().views():
272:             return False
273:         return True

Related:

  1. event listener callback error #12 event listener callback error
evandrocoan added a commit to evandroforks/ANSIescape that referenced this issue Oct 13, 2017
evandrocoan added a commit to evandroforks/ANSIescape that referenced this issue Jan 11, 2018
@giampaolo
Copy link

Despite this is an old issue, it is still valid today. I cannot tell how to reproduce it, but I experience it kind of regularly (say once per week):

Traceback (most recent call last):
  File "/home/giampaolo/.config/sublime-text/Installed Packages/ANSIescape.sublime-package/ansi.py", line 343, in check_left_ansi
    if not self._is_view_valid(view):
  File "/home/giampaolo/.config/sublime-text/Installed Packages/ANSIescape.sublime-package/ansi.py", line 377, in _is_view_valid
    if view not in view.window().views():
AttributeError: 'NoneType' object has no attribute 'views'

It appears like a simple race condition: view.window() exists at line 373 but disappears at 377:

SublimeANSI/ansi.py

Lines 372 to 379 in c8f45de

def _is_view_valid(self, view):
if view.window() is None:
return False
if view.window() not in sublime.windows():
return False
if view not in view.window().views():
return False
return True

The bugfix appears simple: save the view.window() object in a variable at the beginning of the function. AFAICT the solution proposed in #48 appears correct. Is it possible to merge that or a variant of it?

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

2 participants