pi-lens
Version:
Real-time code feedback for pi — LSP, linters, formatters, type-checking, structural analysis & booboo
62 lines (51 loc) • 2.4 kB
YAML
# Python Slop Detection
# Detects method names from other languages (JS/Java/Ruby/Go/C#/PHP) used in Python.
# These are syntactically valid calls but don't exist on Python objects — runtime AttributeError.
id: python-cross-language-method
name: Cross-Language Method Leakage
severity: warning
category: correctness
defect_class: hallucination
inline_tier: warning
language: python
message: "'{{METHOD}}' is not a Python method — likely a cross-language idiom leaking in"
description: |
A method name from another language is being called on a Python object.
These cause AttributeError at runtime. Common AI confusion pattern.
Examples by language:
- JavaScript: .push() → .append(), .forEach() → for loop, .includes() → in
- Java: .equals() → ==, .isEmpty() → not obj, .println() → print()
- Ruby: .each() → for loop, .collect() → list comprehension
- C#: .Add() → .append(), .Contains() → in, .ToLower() → .lower()
- PHP: strlen() as method → len()
query: |
(call
function: (attribute
object: (_) @OBJ
attribute: (identifier) @METHOD)
(#match? @METHOD "^(push|forEach|indexOf|charAt|substring|hasOwnProperty|unshift|flatMap|padStart|padEnd|trimStart|trimEnd|equals|isEmpty|println|printf|getClass|hashCode|toCharArray|getBytes|compareTo|equalsIgnoreCase|startsWith|endsWith|each|collect|reject|detect|inject|chomp|chop|gsub|upcase|downcase|present|blank|Add|Contains|ToLower|ToUpper|Trim|Substring|WriteLine|ReadLine|TryParse|forEach|includes|assign|freeze|splice|unshift|shift|flatMap)$"))
metavars:
- OBJ
- METHOD
post_filter: match_captures
post_filter_params:
METHOD: "^(push|forEach|indexOf|charAt|substring|hasOwnProperty|unshift|flatMap|padStart|padEnd|trimStart|trimEnd|equals|isEmpty|println|printf|getClass|hashCode|toCharArray|getBytes|compareTo|equalsIgnoreCase|startsWith|endsWith|each|collect|reject|detect|inject|chomp|chop|gsub|upcase|downcase|present|blank|Add|Contains|ToLower|ToUpper|Trim|Substring|WriteLine|ReadLine|TryParse|forEach|includes|assign|freeze|splice|unshift|shift|flatMap)$"
has_fix: false
tags:
- python
- correctness
- hallucination
- slop
- cross-language
- ai-generated
examples:
bad: |
items.push(x)
name.equals("foo")
lst.forEach(lambda x: print(x))
s.isEmpty()
good: |
items.append(x)
name == "foo"
for x in lst: print(x)
not s