diff --git a/newsfragments/84.feature.rst b/newsfragments/84.feature.rst new file mode 100644 index 0000000..d421bb3 --- /dev/null +++ b/newsfragments/84.feature.rst @@ -0,0 +1 @@ +Add public methods ``unasync_name`` and ``unasync_string`` to ``Rule`` to allow for easier customization via inheritance. diff --git a/src/unasync/__init__.py b/src/unasync/__init__.py index e669b9a..6cfa78d 100644 --- a/src/unasync/__init__.py +++ b/src/unasync/__init__.py @@ -89,20 +89,20 @@ def _unasync_tokens(self, tokens): skip_next = True else: if token.name == "NAME": - token = token._replace(src=self._unasync_name(token.src)) + token = token._replace(src=self.unasync_name(token.src)) elif token.name == "STRING": - left_quote, name, right_quote = ( + left_quote, string, right_quote = ( token.src[0], token.src[1:-1], token.src[-1], ) token = token._replace( - src=left_quote + self._unasync_name(name) + right_quote + src=left_quote + self.unasync_string(string) + right_quote ) yield token - def _unasync_name(self, name): + def unasync_name(self, name): if name in self.token_replacements: return self.token_replacements[name] # Convert classes prefixed with 'Async' into 'Sync' @@ -110,6 +110,9 @@ def _unasync_name(self, name): return "Sync" + name[5:] return name + def unasync_string(self, string): + return self.unasync_name(string) + def unasync_files(fpath_list, rules): for f in fpath_list: