Просмотр исходного кода

Use set instead of list for flaskbb_modules

Gets rid of an error in Python 2 which tried to register
'None' plugins.
Peter Justin 7 лет назад
Родитель
Сommit
d9753f99ef
1 измененных файлов с 6 добавлено и 4 удалено
  1. 6 4
      flaskbb/app.py

+ 6 - 4
flaskbb/app.py

@@ -21,7 +21,7 @@ from sqlalchemy.exc import OperationalError, ProgrammingError
 from flask import Flask, request
 from flask import Flask, request
 from flask_login import current_user
 from flask_login import current_user
 
 
-from flaskbb._compat import string_types
+from flaskbb._compat import string_types, iteritems
 # views
 # views
 from flaskbb.user.views import user
 from flaskbb.user.views import user
 from flaskbb.message.views import message
 from flaskbb.message.views import message
@@ -413,10 +413,12 @@ def load_plugins(app):
     # have to find all the flaskbb modules that are loaded this way
     # have to find all the flaskbb modules that are loaded this way
     # otherwise sys.modules might change while we're iterating it
     # otherwise sys.modules might change while we're iterating it
     # because of imports and that makes Python very unhappy
     # because of imports and that makes Python very unhappy
-    flaskbb_modules = [
-        module for name, module in sys.modules.items()
+    # Converting it to a set is neccessary because we are not interested
+    # in duplicated plugins or invalid ones ('None' - appears on py2)
+    flaskbb_modules = set(
+        module for name, module in iteritems(sys.modules)
         if name.startswith('flaskbb')
         if name.startswith('flaskbb')
-    ]
+    )
     for module in flaskbb_modules:
     for module in flaskbb_modules:
         app.pluggy.register(module)
         app.pluggy.register(module)
         app.pluggy.mark_as_internal_plugin(module)
         app.pluggy.mark_as_internal_plugin(module)