sourcery-ai / sourcery

Instant AI code reviews
https://sourcery.ai
MIT License
1.51k stars 65 forks source link

Variable name `_` (underscore) triggers avoid-single-character-names-variables. #315

Closed gsnidero closed 1 year ago

gsnidero commented 1 year ago

Description

A variable named _ (underscore) sometimes triggers the "Avoid single character names (avoid-single-character-names-variables)" rule.

Code snippet that reproduces issue

# here is OK
for _ in range(5):
    print("hello")

def func(number: int) -> int:
    ...

# here triggers "Avoid single character names (avoid-single-character-names-variables)"
_ = func(10)

Debug Information

IDE Version: VSCode Version: 1.74.3 (Universal) Sourcery Version: v1.0.3 Operating system and Version: Apple M1 Pro, macOS 13.1 (22C65),

bm424 commented 1 year ago

Hi @gsnidero, thanks for reaching out. The avoid-single-character-names-variables rule is based on the Google Python Style Guide, which we're trying to follow closely, and as a result I think this trigger is correct, so I'm going to close this issue.

If you'd prefer different behaviour, you can disable this rule and instead write your own into your .sourcery.yaml config file - the documentation here and the rule definition here should help get you started.

gsnidero commented 1 year ago

Hi @bm424, ok – I was thinking at the common use of _ as a "throwaway variable" e.g.. Thank you for the quick reply.