File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -53,11 +53,12 @@ def capwords(s, sep=None):
5353
5454
5555class _TemplatePattern :
56+ # This descriptor is overwritten in ``Template._compile_pattern()``.
5657 def __get__ (self , instance , cls = None ):
5758 if cls is None :
5859 return self
59- # This descriptor is overwritten in ``_compile_pattern()``.
6060 return cls ._compile_pattern ()
61+ _TemplatePattern = _TemplatePattern ()
6162
6263
6364class Template :
@@ -72,7 +73,7 @@ class Template:
7273 braceidpattern = None
7374 flags = None # default: re.IGNORECASE
7475
75- pattern = _TemplatePattern () # use a descriptor to compile the pattern
76+ pattern = _TemplatePattern # use a descriptor to compile the pattern
7677
7778 def __init_subclass__ (cls ):
7879 super ().__init_subclass__ ()
@@ -83,7 +84,7 @@ def _compile_pattern(cls):
8384 import re # deferred import, for performance
8485
8586 cls_pattern = cls .__dict__ .get ('pattern' )
86- if cls_pattern and not isinstance ( cls_pattern , _TemplatePattern ) :
87+ if cls_pattern is not None and cls_pattern is not _TemplatePattern :
8788 # Prefer a pattern defined on the class.
8889 pattern = cls_pattern
8990 else :
You can’t perform that action at this time.
0 commit comments