Download tasks/pygments__pygments-cinst-e08f9c27/solution/patch.diff from Essacheez/r2e-code-instruct-qwen3.5: direct link, hf CLI and curl.
- Browser
- Download file 973 Bytes
-
https://huggingface.co/datasets/Essacheez/r2e-code-instruct-qwen3.5/resolve/main/tasks/pygments__pygments-cinst-e08f9c27/solution/patch.diff
- Command line
-
hf download hf://datasets/Essacheez/r2e-code-instruct-qwen3.5/tasks/pygments__pygments-cinst-e08f9c27/solution/patch.diff
-
curl -L -o patch.diff https://huggingface.co/datasets/Essacheez/r2e-code-instruct-qwen3.5/resolve/main/tasks/pygments__pygments-cinst-e08f9c27/solution/patch.diff
973 Bytes
| diff --git a/task_module.py b/task_module.py | |
| new file mode 100644 | |
| index 0000000..0000001 | |
| --- /dev/null | |
| +++ b/task_module.py | |
| +from pygments.lexers import PythonLexer | |
| +from pygments import token | |
| + | |
| +class CodeAnalyzer: | |
| + """Analyzes Python code using pygments tokenization.""" | |
| + | |
| + def __init__(self): | |
| + self._lexer = PythonLexer() | |
| + | |
| + def count_docstrings(self, source): | |
| + """Count the number of String.Doc tokens in the source code.""" | |
| + if not isinstance(source, str): | |
| + raise TypeError("Source must be a string") | |
| + | |
| + # Get tokens using pygments | |
| + # Note: get_tokens returns an iterator of (TokenType, value) tuples | |
| + tokens = list(self._lexer.get_tokens(source)) | |
| + | |
| + count = 0 | |
| + for token_type, value in tokens: | |
| + if token_type == token.String.Doc: | |
| + count += 1 | |
| + | |
| + return count | |
| \ No newline at end of file | |