-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
11 changed files
with
475 additions
and
184 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
"""Module that provides utilities related to comments. | ||
This is separate from pyink.ink to avoid circular dependencies. | ||
""" | ||
|
||
import re | ||
|
||
from pyink.mode import Mode | ||
|
||
|
||
def comment_contains_pragma(comment: str, mode: Mode) -> bool: | ||
"""Check if the given string contains one of the pragma forms. | ||
A pragma form can appear at the beginning of a comment: | ||
# pytype: disable=attribute-error | ||
or somewhere in the middle: | ||
# some comment # type: ignore # another comment | ||
or the comments can even be separated by a semicolon: | ||
# some comment; noqa: E111; another comment | ||
Args: | ||
comment: The comment to check. | ||
mode: The mode that defines which pragma forms to check for. | ||
Returns: | ||
True if the comment contains one of the pragma forms. | ||
""" | ||
joined_pragma_expression = "|".join(mode.pyink_annotation_pragmas) | ||
pragma_regex = re.compile(rf"([#|;] ?(?:{joined_pragma_expression}))") | ||
return pragma_regex.search(comment) is not None |
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
Oops, something went wrong.