tessl install tessl/pypi-wtfpython@3.0.0Educational collection of surprising Python code snippets that demonstrate counter-intuitive behaviors and language internals
Agent Success
Agent success rate when using this tile
93%
Improvement
Agent success rate improvement when using this tile compared to baseline
1.06x
Baseline
Agent success rate without this tile
88%
Build a tool that validates Python identifiers for potential security issues caused by Unicode lookalike characters. The tool should detect when identifiers contain characters that visually resemble ASCII letters but are actually different Unicode code points (such as Cyrillic characters).
Create a Python module that provides functionality to:
Analyze identifiers: Check if a given string contains Unicode lookalike characters that could cause confusion with ASCII characters.
Report findings: For each suspicious identifier, report:
Categorize risk level: Classify identifiers as:
safe: Contains only ASCII characterssuspicious: Contains Unicode characters that look similar to ASCIImixed: Contains both ASCII and non-ASCII characters without visual confusion@generates
def analyze_identifier(identifier: str) -> dict:
"""
Analyze a Python identifier for Unicode lookalike characters.
Args:
identifier: The string to analyze
Returns:
A dictionary containing:
- 'risk_level': str - 'safe', 'suspicious', or 'mixed'
- 'lookalikes': list[dict] - List of lookalike character info
Each dict contains:
- 'char': str - The suspicious character
- 'code_point': str - Unicode code point (e.g., 'U+04BB')
- 'resembles': str - The ASCII character it resembles
- 'position': int - Position in the identifier
"""
passProvides access to Unicode character database for character name and category lookup.