Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Report useless ternary operator #1706

Open
orsinium opened this issue Oct 29, 2020 · 26 comments
Open

Report useless ternary operator #1706

orsinium opened this issue Oct 29, 2020 · 26 comments
Labels
good first issue Entrypoint to the project Hacktoberfest Hactoberfest fun! help wanted Extra attention is needed level:starter Good for newcomers rule request Adding a new rule

Comments

@orsinium
Copy link
Collaborator

orsinium commented Oct 29, 2020

Rule request

Thesis

Detect if both possible results of a ternary operator return the same value.

# bad
# (all results below can be replaced by just `a`)
a if ... else a
a if a is not None else None
a if a != b else b
b if a == b else a

# ok
a if ... else c
a.split() if a is not None else None
a if a != b else c

Reasoning

It is either a bug or unnecessary complexity.

@orsinium orsinium added the rule request Adding a new rule label Oct 29, 2020
@sobolevn sobolevn added this to the Version 0.15 aka Python3.9 milestone Oct 29, 2020
@sobolevn sobolevn added good first issue Entrypoint to the project Hacktoberfest Hactoberfest fun! help wanted Extra attention is needed level:starter Good for newcomers labels Oct 29, 2020
@locko62

This comment has been minimized.

@sobolevn
Copy link
Member

sobolevn commented Nov 9, 2020

@locko62 does it mean that you want to wrok on this issue? 🙂

@Praveenk8051
Copy link

Hello, I would like to work on this? This is my first-time!

@sobolevn
Copy link
Member

sobolevn commented Nov 9, 2020

@Praveenk8051
Copy link

Thank you!

@Praveenk8051
Copy link

Praveenk8051 commented Nov 10, 2020

Hi, I need some help.
I went through documentation to know how to contribute and API References

I'm facing below error when I'm executing make test. Can you please help me with it ? @sobolevn
wemake

I don't think i can just go ahead and install.
Thanks!

@sobolevn
Copy link
Member

I can recommend to remove your venv, make sure that your base python does not have any installed packages that might be causing this problem (check with pip freeze, it should be empty), and call poetry install once again after cleaning everything.

@Praveenk8051
Copy link

Worked. Thank you!

@Praveenk8051
Copy link

Hello, I'm trying to debug and apply changes so that linter is applicable properly for ternary properties. But I'm failing to understand how to proceed. Can you please help me with it ? @sobolevn

This happens to be present in compares.py where NestedTernaryViolation is checked. Am I on right path ? Should i check and tweak in compares.py

@sobolevn
Copy link
Member

Yes, please fix all the violations in our own source code found by a new rule!

@amansr02
Copy link

amansr02 commented Apr 7, 2021

Hello @sobolevn. I would also like to work on this issue apart from #1974 with @bhargavi247. We are students who are working on an assignment to fix Issues for open source projects. Do let us know if this issue is still open! Thank you!

@sobolevn
Copy link
Member

sobolevn commented Apr 7, 2021

Yes, it is! Thanks!

@amansr02
Copy link

amansr02 commented Apr 7, 2021

Awesome! Let us get started on this issue as well. If you could assign it to @bhargavi247 that would be great.

@bhargavi247
Copy link

Thanks @sobolevn ! Would love to get assigned to this task :)

@sobolevn sobolevn assigned bhargavi247 and unassigned Praveenk8051 Apr 8, 2021
@harshakhmk
Copy link

harshakhmk commented Jun 4, 2021

I would like to work on this issue, I am a first-time contributor
Can someone guide me on how to proceed with this issue?

@sobolevn sobolevn assigned harshakhmk and unassigned bhargavi247 Jun 4, 2021
@sobolevn
Copy link
Member

sobolevn commented Jun 4, 2021

@mketer1
Copy link

mketer1 commented Mar 22, 2022

Hi! I'm fairly new to open source contribution but would like to give this issue a try. If this issue is unclaimed, could I possibly be assigned. Also, if I do need assistance, would I be able to receive guidance from other contributors in this repository?

@adlizone
Copy link

This is hot....does anyone have the idea how to write a visitor for this

@adlizone
Copy link

adlizone commented Feb 7, 2023

#2579

@FieldMarshallObvious
Copy link

Is this issue still open? If so I would be interested in being assigned to this issue. Like many others here also new to open source and would appreciate the opportunity to learn.

@sobolevn
Copy link
Member

sobolevn commented Mar 8, 2024

@FieldMarshallObvious please, go ahead :)

@sobolevn
Copy link
Member

sobolevn commented Mar 8, 2024

you can take a look at #2579
it was a promising start, but never fixed tests :(

@FieldMarshallObvious
Copy link

Thanks! Will do 👍

@FieldMarshallObvious
Copy link

Attempt to fix this on PR #2902

@sobolevn
Copy link
Member

sobolevn commented Apr 1, 2024

@FieldMarshallObvious is working on it right now, please take some other issue :)
There are multiple ones that are free!

@CodeCraftsman481
Copy link

@sobolevn Can you please suggest other issues for beginners?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Entrypoint to the project Hacktoberfest Hactoberfest fun! help wanted Extra attention is needed level:starter Good for newcomers rule request Adding a new rule
Projects
None yet
Development

No branches or pull requests