1
+ from __future__ import annotations
2
+
1
3
import contextlib
2
4
import logging
3
5
import os
4
6
import re
5
7
from fnmatch import fnmatch
6
8
from importlib import import_module
7
- from typing import Set
8
9
9
10
from django .template import engines
10
11
from django .utils .encoding import smart_str
@@ -68,9 +69,9 @@ def _get_loaders(self):
68
69
loaders .append (loader )
69
70
return loaders
70
71
71
- def _get_paths (self ) -> Set :
72
+ def _get_paths (self ) -> set [ str ] :
72
73
"""Obtains a set of all template directories."""
73
- paths = set ()
74
+ paths : set [ str ] = set ()
74
75
for loader in self ._get_loaders ():
75
76
with contextlib .suppress (ImportError , AttributeError , TypeError ):
76
77
module = import_module (loader .__module__ )
@@ -80,12 +81,12 @@ def _get_paths(self) -> Set:
80
81
paths .update (smart_str (origin ) for origin in get_template_sources ("" ))
81
82
return paths
82
83
83
- def _get_templates (self , paths : Set ) -> Set :
84
+ def _get_templates (self , paths : set [ str ] ) -> set [ str ] :
84
85
"""Obtains a set of all HTML template paths."""
85
86
extensions = [".html" ]
86
- templates = set ()
87
+ templates : set [ str ] = set ()
87
88
for path in paths :
88
- for root , dirs , files in os .walk (path , followlinks = False ):
89
+ for root , _ , files in os .walk (path , followlinks = False ):
89
90
templates .update (
90
91
os .path .join (root , name )
91
92
for name in files
@@ -95,9 +96,9 @@ def _get_templates(self, paths: Set) -> Set:
95
96
96
97
return templates
97
98
98
- def _get_components (self , templates : Set ) -> Set :
99
+ def _get_components (self , templates : set [ str ] ) -> set [ str ] :
99
100
"""Obtains a set of all IDOM components by parsing HTML templates."""
100
- components = set ()
101
+ components : set [ str ] = set ()
101
102
for template in templates :
102
103
with contextlib .suppress (Exception ):
103
104
with open (template , "r" , encoding = "utf-8" ) as template_file :
@@ -118,7 +119,7 @@ def _get_components(self, templates: Set) -> Set:
118
119
)
119
120
return components
120
121
121
- def _register_components (self , components : Set ) -> None :
122
+ def _register_components (self , components : set [ str ] ) -> None :
122
123
"""Registers all IDOM components in an iterable."""
123
124
for component in components :
124
125
try :
0 commit comments