-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create a file for the base classes for Formatters
- Loading branch information
1 parent
76e8df0
commit 64774ee
Showing
2 changed files
with
28 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import abc | ||
import tokenize | ||
|
||
|
||
class Formatter: | ||
"""Base class for docstring formatter""" | ||
|
||
@abc.abstractmethod | ||
def treat_token(self, tokeninfo: tokenize.TokenInfo) -> tokenize.TokenInfo: | ||
"""Return a modified token""" | ||
|
||
|
||
class StringFormatter(Formatter): | ||
"""Base class for formatter that only modifies the string content""" | ||
|
||
@abc.abstractmethod | ||
def _treat_string(self, tokeninfo: tokenize.TokenInfo) -> str: | ||
"""Return a modified string""" | ||
|
||
def treat_token(self, tokeninfo: tokenize.TokenInfo) -> tokenize.TokenInfo: | ||
return tokenize.TokenInfo( | ||
tokeninfo.type, | ||
self._treat_string(tokeninfo), | ||
tokeninfo.start, | ||
tokeninfo.end, | ||
tokeninfo.line, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters