-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #244 from reagento/fix/lambda-coercer
Fix SyntaxError with lambda in coercer (#243)
- Loading branch information
Showing
8 changed files
with
50 additions
and
27 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 @@ | ||
Fix SyntaxError with lambda in :func:`.coercer` |
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,21 @@ | ||
import re | ||
import string | ||
from abc import ABC, abstractmethod | ||
|
||
|
||
class NameSanitizer(ABC): | ||
@abstractmethod | ||
def sanitize(self, name: str) -> str: | ||
... | ||
|
||
|
||
class BuiltinNameSanitizer(NameSanitizer): | ||
_BAD_CHARS = re.compile(r'\W') | ||
_TRANSLATE_MAP = str.maketrans({'.': '_', '[': '_'}) | ||
|
||
def sanitize(self, name: str) -> str: | ||
if name == "": | ||
return "" | ||
|
||
first_letter = name[0] if name[0] in string.ascii_letters else '_' | ||
return first_letter + self._BAD_CHARS.sub('', name[1:].translate(self._TRANSLATE_MAP)) |
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
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
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
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
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
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