I just installed and enabled all the rules by setting select = [ "ALL" ]
And then looked at the 'errors' it showed me for my existing code base and then excluded some rules which don't interest me.
I also have it set up in my IDE, so it'll show me the linting errors while coding.
In a larger code base there will definitely be many 'errors', but using it cleaned up my code really good and it stopped me from some footguns.
https://github.com/simonw/datasette https://github.com/simonw/sqlite-utils
So, his code might not be a good place to find best patterns (for ex, I don't think they are fully typed), but his repos are very pragmatic, and his development process is super insightful (well documented PRs for personal repos!). Best part, he blogs about every non-trivial update, so you get all the context!
The entire point is not to just mindlessly consume a code base, but instead form an idea of how to approach the problem and then see if your hypothesis is correct. Then comparing your approach to the actual approach.
This can show you things that you might've missed taking into account.
For example, gallery-dl's incidental complexity all lies in centralizing persistent state, logging, and IO through the CLI. It doesn't have sufficient abstraction to allow it to be rewired to different UIs without relying on internal APIs that have no guarantee that won't change.
Meanwhile a similar application in yt-dlp has that abstraction and works better, but has similar complexity in the configuration side of things.
I agree with others that code formatters like black or ruff might be helpful to you. The literature surrounding them, such as PEPs concerning code formatting, often include examples you may find useful.
Here's an excerpt from the readme: "Beyond Jupyter is a collection of self-study materials on software design, with a specific focus on machine learning applications, which demonstrates how sound software design can accelerate both development and experimentation."
This one came in handy not too long ago: https://github.com/openai/openai-cookbook/blob/main/examples...
On that subject, Raymond Hettinger has a great talk called “Beyond Pep8” that talks about how to de-java your codebase among other things. Also reading the book Fluent Python now and it is so far excellent.
It is an improvement for the the tiny but efficient web2py web framework.
It's relatively small and I think the main take away would be the use of Protocols for the pluggable backend system. I hope you get something out of it :)
Grind this out painstakingly and then copy and paste that as boilerplate for the rest of your natural life.
Flask, in particular, has a very small number of open issues (2) for a project that is pretty popular. Its also maintained by a competent team and has a lot of project best practices.
https://github.com/pallets/flask
https://pypistats.org/packages/flask
https://pypistats.org/packages/django (for comparison)
Avoid anything developed/maintained by one corporation. In general, their organizational hierarchy leads to bad patterns and resists useful changes that don't conform to the goals and patterns of the business or engineering leads. Grassroots OSS projects aren't always better, but they're less likely to have a monoculture and perverse incentives.
The Architecture of Open Source Applications
https://github.com/amontalenti/elements-of-python-style#some...
The style guide itself, published a few years back, also has some suggestions with small code snippets.
Not exactly small, but great.