Skip to content

Conversation

@cclauss
Copy link

@cclauss cclauss commented Dec 20, 2025

https://docs.astral.sh/ruff/rules/#flake8-simplify-sim

% ruff check --select=SIM --ignore=SIM102,SIM117 --statistics

5	SIM201	[ ] negate-equal-op
4	SIM108	[ ] if-else-block-instead-of-if-exp
4	SIM300	[*] yoda-conditions
2	SIM105	[ ] suppressible-exception
1	SIM118	[ ] in-dict-keys
1	SIM905	[*] split-static-string
1	SIM910	[*] dict-get-with-none-default
Found 18 errors.

@alexfikl
Copy link
Collaborator

Any reason in particular you want these in? In my experience the SIM rules are quite opinionated, so I wasn't very inclined to turn them on.

@cclauss
Copy link
Author

cclauss commented Dec 20, 2025

SIM rules are primarily designed to simplify readability when transitioning from one project to another. If they do not correspond to this project's needs, then this PR can be closed.

Copy link
Collaborator

@alexfikl alexfikl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not against it, so if you want to work on it some more, we can add them. I left some comments from a quick look. Let me know what you think!

picked_documents = documents
else:
picked_documents = list(papis.api.pick_doc(documents))
picked_documents = documents if all_ else list(papis.api.pick_doc(documents))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you disable SIM108? This might be personal preference, but I've never liked putting the condition in the middle (likely because of all the normal ifs).

Comment on lines -95 to -97
elif key == "files":
if not check_files(document):
result.append({"doc": document, "key": key, "msg": "Missing files"})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you disable SIM102? This was most written as a "switch on each [KEY] type and do [THING]", so combing the ifs is a bit confusing.

)

if not len(troubled_docs) == 0:
if len(troubled_docs) != 0:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't the pythonic way to do with if not troubled_docs?

Comment on lines +30 to +38
with t.button(cls="btn btn-success",
type="submit"):
wh.icon_span("cloud-bolt", "Fetch citations")
if "doi" in doc:
quoted_doi = urllib.parse.quote(doc["doi"], safe="")
with t.a(cls="btn btn-primary",
target="_blank",
href=ads_fmt.format(doi=quoted_doi)):
wh.icon_span("globe", "ads")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the reasoning here (to abuse the nesting) was to match the HTML tags better. I'm not sure it's an improvement to group them?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants