@@ -76,6 +76,12 @@ class ExpandedHookDict(_BaseExpandedHookDict):
7676 priority : int
7777
7878
79+ def _normalise_name (name : str ) -> str :
80+ # this package
81+ from formate .utils import _normalize_pattern
82+
83+ return _normalize_pattern .sub ('-' , name ).lower ()
84+
7985@pretty_repr
8086@serde
8187@attrs .define
@@ -87,7 +93,7 @@ class Hook:
8793 """
8894
8995 #: The name of the hook. The name is normalized into lowercase, with underscores replaced by hyphens.
90- name : str = attrs .field ()
96+ name : str = attrs .field (converter = _normalise_name )
9197
9298 #: The priority of the hook.
9399 priority : int = attrs .field (default = 10 )
@@ -103,13 +109,6 @@ class Hook:
103109 #: A read-only view on the global configuration mapping, for hooks to do with as they wish.
104110 global_config : Mapping [str , Any ] = attrs .field (factory = dict )
105111
106- @name .validator
107- def _normalize (self , attribute , value ): # noqa: MAN001,MAN002
108- # this package
109- from formate .utils import _normalize_pattern
110-
111- self .name = _normalize_pattern .sub ('-' , value ).lower ()
112-
113112 @classmethod
114113 def parse (cls , data : HooksMapping ) -> Iterator ["Hook" ]:
115114 r"""
@@ -161,18 +160,11 @@ class EntryPoint:
161160 """
162161
163162 #: The name of the entry point. The name is normalized into lowercase, with underscores replaced by hyphens.
164- name : str = attrs .field ()
163+ name : str = attrs .field (converter = _normalise_name )
165164
166165 #: The object the entry point refers to.
167166 obj : Callable [..., str ] = attrs .field ()
168167
169- @name .validator
170- def _normalize (self , attribute , value ): # noqa: MAN001,MAN002
171- # this package
172- from formate .utils import _normalize_pattern
173-
174- self .name = _normalize_pattern .sub ('-' , value ).lower ()
175-
176168 @obj .validator
177169 def _validate_obj (self , attribute , value ): # noqa: MAN001,MAN002
178170 if not callable (value ):
0 commit comments