Skip to content

Commit 75e4d6e

Browse files
Fix typo in iter_models, refctoring (#415)
1 parent a214e7c commit 75e4d6e

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

src/dipdup/utils/database.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -104,21 +104,24 @@ def is_model_class(obj: Any) -> bool:
104104

105105
def iter_models(package: Optional[str]) -> Iterator[Tuple[str, Type[Model]]]:
106106
"""Iterate over built-in and project's models"""
107-
if package and not package.endswith('.models'):
108-
package += '.models'
107+
modules = [
108+
('int_models', importlib.import_module('dipdup.models')),
109+
]
109110

110-
modules = [importlib.import_module('dipdup.models')]
111111
if package:
112-
modules.append(importlib.import_module(package))
113-
114-
for models_module in modules:
115-
for attr in dir(models_module):
112+
if not package.endswith('.models'):
113+
package += '.models'
114+
modules.append(
115+
('models', importlib.import_module(package)),
116+
)
117+
118+
for app, module in modules:
119+
for attr in dir(module):
116120
if attr.startswith('_'):
117121
continue
118122

119-
attr_value = getattr(models_module, attr)
123+
attr_value = getattr(module, attr)
120124
if is_model_class(attr_value):
121-
app = 'int_models' if attr_value.__name__ == 'dipdup.models' else 'models'
122125
yield app, attr_value
123126

124127

0 commit comments

Comments
 (0)