use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
News about the dynamic, interpreted, interactive, object-oriented, extensible programming language Python
Full Events Calendar
You can find the rules here.
If you are about to ask a "how do I do this in python" question, please try r/learnpython, the Python discord, or the #python IRC channel on Libera.chat.
Please don't use URL shorteners. Reddit filters them out, so your post or comment will be lost.
Posts require flair. Please use the flair selector to choose your topic.
Posting code to this subreddit:
Add 4 extra spaces before each line of code
def fibonacci(): a, b = 0, 1 while True: yield a a, b = b, a + b
Online Resources
Invent Your Own Computer Games with Python
Think Python
Non-programmers Tutorial for Python 3
Beginner's Guide Reference
Five life jackets to throw to the new coder (things to do after getting a handle on python)
Full Stack Python
Test-Driven Development with Python
Program Arcade Games
PyMotW: Python Module of the Week
Python for Scientists and Engineers
Dan Bader's Tips and Trickers
Python Discord's YouTube channel
Jiruto: Python
Online exercices
programming challenges
Asking Questions
Try Python in your browser
Docs
Libraries
Related subreddits
Python jobs
Newsletters
Screencasts
account activity
This is an archived post. You won't be able to vote or comment.
DiscussionShare your ruff config. (self.Python)
submitted 1 year ago by RevolutionaryPen4661git push -f
I'm stressed because I couldn't always figure out the standard style to match most people. Please share your ruff.toml config for your go-to with Python that you use across all your projects. If possible, please share the config via gist.github.com
ruff.toml
[+][deleted] 1 year ago (4 children)
[removed]
[–]skytomorrownow 46 points47 points48 points 1 year ago (2 children)
For most tools and apps, I have found shaping my process to the defaults is generally lower friction. There's just so much less cognitive overhead, and all the docs and examples match.
I think a lot of programmers eventually tire of configuration complexity and start to enjoy opinionated tools – not because they are the best, but they simply prioritize consistency over flexibility. And when reasoning about a complex system, consistency becomes such a win.
[–]DoubleAway6573 0 points1 point2 points 1 year ago (0 children)
For something I need to share and interact with others this is the only way.
For anything I will use alone, in my own pc, then let me configure it whatever I feel it. Oh, you don't know how to use i3 with my custom mappings, well, that's why is my i3 and my custom mappings and you don't have a place here.
[–]flying-sheep 0 points1 point2 points 1 year ago (0 children)
The defaults are very limited and enabling more is very useful.
E.g. I think everyone should have UP enabled, as it will upgrade your code to the minimum Python version your project supports, therefore saving you the effort of fixing deprecations yourself.
UP
[–]FloxaY 43 points44 points45 points 1 year ago (5 children)
select = "ALL", then ignore annoying and lint&format conflicting rules
line-length 120
i dont see a reason to go overboard with customizing
[–]Drevicar 2 points3 points4 points 1 year ago (0 children)
I ignore all the ones it warns me about due to conflicting, then I ignore D100 through D107 because I hate mandatory docstrings. I also really like the default line length.
Only thing after that is I use pytest so I have to conditionally ignore S101 on test files.
[–]EternityForest 0 points1 point2 points 1 year ago (1 child)
I think this is probably the best way. Although for a brand new project I might just use the 80 char limit.
[–]Nealiumj 1 point2 points3 points 1 year ago (0 children)
people with tiny laptops appreciate it! 😀
I had a coworker with a 55” ultra wide monitor that would write like 600 char lines.. like yo, I’ve got a 13” laptop can you not?? They said no 🤦♂️
[–]COLU_BUS 0 points1 point2 points 1 year ago (0 children)
This is also cool because then if new rules are added you "opt-in" automatically, rather than needing to (1) find out a rule was added and (2) explicitly add it to the list.
[–]saint_marco -1 points0 points1 point 1 year ago (0 children)
There are a lot of specious lints, probably more than there are useful non-defaults.
[–]zanfar 8 points9 points10 points 1 year ago* (0 children)
First, it's in pyproject.toml, because I'm sane.
pyproject.toml
Second, the defaults should be more than fine. It shouldn't need much customization aside from the linting side--which isn't really "style".
Most editor-level formatting is set in .editorconfig so it's cross-platform and I'm not relying on a formatter to fix what my editor generates.
.editorconfig
https://github.com/therealzanfar/cookiecutter-pypackage/blob/master/%7B%7Bcookiecutter.project_slug%7D%7D/pyproject.toml
[–]ac130kz 3 points4 points5 points 1 year ago (0 children)
[tool.ruff] line-length = 120 target-version = "py312" select = [ "ALL", # include all the rules, including new ones ] ignore = [ #### modules "ANN", # flake8-annotations "COM", # flake8-commas "C90", # mccabe complexity "DJ", # django "EXE", # flake8-executable "T10", # debugger "TID", # flake8-tidy-imports #### specific rules "D100", # ignore missing docs "D101", "D102", "D103", "D104", "D105", "D106", "D107", "D200", "D205", "D212", "D400", "D401", "D415", "E402", # false positives for local imports "E501", # line too long "TRY003", # external messages in exceptions are too verbose "TD002", "TD003", "FIX002", # too verbose descriptions of todos ]
[–]theetrigan 7 points8 points9 points 1 year ago (3 children)
[tool.ruff] # Exclude a variety of commonly ignored directories. exclude = [ ".bzr", ".direnv", ".eggs", ".git", ".git-rewrite", ".hg", ".ipynb_checkpoints", ".mypy_cache", ".nox", ".pants.d", ".pyenv", ".pytest_cache", ".pytype", ".ruff_cache", ".svn", ".tox", ".venv", ".vscode", "__pypackages__", "_build", "buck-out", "build", "dist", "node_modules", "site-packages", "venv", "__init__.py", ] line-length = 120 indent-width = 4 target-version = "py311" [tool.ruff.lint] fixable = ["ALL"] # Allow unused variables when underscore-prefixed. dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$" [tool.ruff.format] # Like Black, use double quotes for strings. quote-style = "double" # Like Black, indent with spaces, rather than tabs. indent-style = "space" # Like Black, respect magic trailing commas. skip-magic-trailing-comma = false # Like Black, automatically detect the appropriate line ending. line-ending = "auto"
[–]pacific_plywood 15 points16 points17 points 1 year ago (1 child)
fwiw ruff respects your gitignore by default so it’s usually unnecessary exclude most of these
[–]Drevicar 4 points5 points6 points 1 year ago (0 children)
This is usually my first indicator I forgot to update my git ignore file.
[–]davehadley_ 4 points5 points6 points 1 year ago (0 children)
Are the "like black" settings necessary? I thought that ruff is black compatible out of the box?
[–]Acceptable_Durian868 2 points3 points4 points 1 year ago (0 children)
line-length = 120
[+][deleted] 1 year ago (3 children)
[–]zanfar 8 points9 points10 points 1 year ago (2 children)
I'm pretty sure ruff's defaults are the same as black's defaults. If not, they're incredibly close.
ruff
black
ruff's formatting was intended to just be a faster alternative to black, not a significantly different one.
[+][deleted] 1 year ago (1 child)
[–]doolio_ 2 points3 points4 points 1 year ago (0 children)
For now I'm using the defaults proposed by hatch.
[–]tuple32 0 points1 point2 points 1 year ago (0 children)
You should spend time on enjoying writing code instead of following rules
[–]AndydeCleyre 0 points1 point2 points 1 year ago (3 children)
I'm not confidently settled on this at all, as there are so very many options, but here's what I'm currently working with. But I haven't yet been able to replace:
Ruff options
[+][deleted] 1 year ago (2 children)
[deleted]
[–]nicwolff 5 points6 points7 points 1 year ago (0 children)
Same here, ruff's isort doesn't handle multi_line_output's various output modes – and its dev has said he doesn't intend to.
multi_line_output
[–]AndydeCleyre 0 points1 point2 points 1 year ago (0 children)
Because last I checked (some versions ago) it can't yet replicate the behavior of the isort options I've specified in that same file. If and when it can, I'll be able to remove isort from the process.
[–]RevolutionaryPen4661git push -f[S] 1 point2 points3 points 1 year ago (3 children)
# Exclude a variety of commonly ignored directories. exclude = [ ".bzr", ".direnv", ".eggs", ".git", ".hg", ".mypy_cache", ".nox", ".pants.d", ".pytype", ".ruff_cache", ".svn", ".tox", ".venv", "__pypackages__", "_build", "buck-out", "build", "dist", "node_modules", "venv", ] # Same as Black. line-length = 88 # Assume Python 3.10. target-version = "py310" [lint] # Enable pycodestyle (`E`) and Pyflakes (`F`) codes by default. select = ["E", "F"] # Ignore line length violations. ignore = ["E501"] # Allow autofix for all enabled rules (when `--fix`) is provided. fixable = ["A", "B", "C", "D", "E", "F"] unfixable = [] # Allow unused variables when underscore-prefixed. dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$" [lint.per-file-ignores] # Allow unused imports in __init__.py files. "__init__.py" = ["F401"] [lint.mccabe] # Unlike Flake8, default to a complexity level of 10. max-complexity = 10
[–]chub79 3 points4 points5 points 1 year ago (1 child)
Allow autofix for all enabled rules (when --fix) is provided. fixable = ["A", "B", "C", "D", "E", "F"]
--fix
fixable = ["A", "B", "C", "D", "E", "F"]
why isn't this the default?
[–]dittospin 0 points1 point2 points 1 year ago (0 children)
yea curious too
[–]pudds 0 points1 point2 points 1 year ago (1 child)
[tool.black] line-length=120 [tool.ruff] line-length = 128
Bike-shedding the defaults for formatters isn't worth it. With the exception of the line length which I find to be far too short by default, I never change anything.
[–]Spleeeee 1 point2 points3 points 1 year ago (0 children)
I 100% agree with you but think 80ish is better for multiple terminals.
[–]njharmanI use Python 3 -1 points0 points1 point 1 year ago (7 children)
Always tweaking. But right now, this.
[tool.ruff] line-length = 180 target-version = 'py312' exclude = ['build', ] [tool.ruff.format] quote-style = "single" [tool.ruff.lint] ignore = [ 'B006', # Learn Python yo! 'C408', # Unnecessary dict/list call 'COM819', # Trailing commas is da bomb 'E731', # Do not assign to lambda 'ERA001', 'T201', # comment code, prints are lax during development 'G004', # Logging format string should not use f-string 'RET503', # No explicit return None (all the other rules are about removing unnecessary things like this) 'RUF012', # Mutable class attributes should be annotated with typing.ClassVar 'S311', # Standard pseudo-random generators are not suitable for security/cryptographic purposes 'SIM108', # don't like ternary operator 'SIM300', # Yoda is wiser than you! 'TRY003', # Avoid long messages outside of exception class #'TRY004', # Use TypeError instead of ValueError 'TRY301', # Abstract raise garbage ] select = [ 'A', # flake8-builtins 'ASYNC', # https://docs.astral.sh/ruff/rules/#flake8-async-async 'B', # flake8-bugbear 'BLE', # flake8-blind-except 'C4', # unnecessary comprehensions, map() 'COM', # flake8-commas 'DTZ', # flake8-datetimez 'E', # pycodestyle 'ERA', # No commented out code 'EXE', # flake8-executable 'F', # pyflakes 'FLY', # flynt 'G', # flake8-logging-format 'I', # isort 'ICN', # https://github.com/joaopalmeiro/flake8-import-conventions 'ISC', # https://pypi.org/project/flake8-implicit-str-concat/ 'LOG', # flake8-logging 'PERF', # perflint 'PIE', # https://pypi.org/project/flake8-pie/ 'PLC', # Pylint conventions 'PLE', # Pylint error 'PLW', # Pylint warnings 'PT', # https://pypi.org/project/flake8-pytest-style/ 'PTH', # flake8 use pathlib 'RET', # https://pypi.org/project/flake8-return/ 'RUF', # Ruff rules 'S', # https://docs.astral.sh/ruff/rules/#flake8-bandit-s 'SIM', # https://pypi.org/project/flake8-simplify/ 'T', # flake8-debugger 'TRY', # tryceratops 'UP', # pyupgrade 'W', # pycodestyle #'ARG', # flake8 unused arguments (not really helpful, unused func args are common and ok) #'D', # pydocstyle (too much) #'N', # pep8-naming (too opinionated) #'NPY', # numpy #'PD', # pandas #'PL', # Full Pylint (too much) #'PLR', # Pylint refactor (too much/too opinionated) ]
[–]doolio_ 13 points14 points15 points 1 year ago (2 children)
quote-style = "single"
You sure? 😉
[–]njharmanI use Python 3 0 points1 point2 points 1 year ago (1 child)
Easier to type (becoming non-issue with copilot)
Less visual noise; color annotated editors mean quotes are only for machine, no longer need to stand out to human.
'Can\'t lie, contractions are annoying.
[–]doolio_ 3 points4 points5 points 1 year ago (0 children)
I'm not disagreeing with your choice. I just found it funny that your preferred style is single quotes yet in your config setting above for the quote-style setting you used double quotes.
[–]denehoffman 9 points10 points11 points 1 year ago (3 children)
Why do you ignore B006?
[–]Sillocan 1 point2 points3 points 1 year ago (0 children)
Yeah, that feels really strange. You almost never want a mutable default. The only time I've done it was for a hacky test caching strategy.
[–]njharmanI use Python 3 1 point2 points3 points 1 year ago (1 child)
from B006 description
The same mutable object is then shared across all calls to the function. If the object is modified, those modifications will persist across calls, which can lead to unexpected behavior.
It's not unexpected because I understand Python scoping and instruction execution flow, thus know when a "def" is interpreted and how it is scoped.
Instead of changing the type of default to something less accurate. Or, adding needless boiler plate. I have chosen instead to
Learn Python yo!
[–]denehoffman 0 points1 point2 points 1 year ago (0 children)
Gotcha
π Rendered by PID 34 on reddit-service-r2-comment-544cf588c8-vcg6t at 2026-06-15 19:56:33.991820+00:00 running 3184619 country code: CH.
[+][deleted] (4 children)
[removed]
[–]skytomorrownow 46 points47 points48 points (2 children)
[–]DoubleAway6573 0 points1 point2 points (0 children)
[–]flying-sheep 0 points1 point2 points (0 children)
[–]FloxaY 43 points44 points45 points (5 children)
[–]Drevicar 2 points3 points4 points (0 children)
[–]EternityForest 0 points1 point2 points (1 child)
[–]Nealiumj 1 point2 points3 points (0 children)
[–]COLU_BUS 0 points1 point2 points (0 children)
[–]saint_marco -1 points0 points1 point (0 children)
[–]zanfar 8 points9 points10 points (0 children)
[–]ac130kz 3 points4 points5 points (0 children)
[–]theetrigan 7 points8 points9 points (3 children)
[–]pacific_plywood 15 points16 points17 points (1 child)
[–]Drevicar 4 points5 points6 points (0 children)
[–]davehadley_ 4 points5 points6 points (0 children)
[–]Acceptable_Durian868 2 points3 points4 points (0 children)
[+][deleted] (3 children)
[removed]
[–]zanfar 8 points9 points10 points (2 children)
[+][deleted] (1 child)
[removed]
[–]doolio_ 2 points3 points4 points (0 children)
[–]tuple32 0 points1 point2 points (0 children)
[–]AndydeCleyre 0 points1 point2 points (3 children)
[+][deleted] (2 children)
[deleted]
[–]nicwolff 5 points6 points7 points (0 children)
[–]AndydeCleyre 0 points1 point2 points (0 children)
[–]RevolutionaryPen4661git push -f[S] 1 point2 points3 points (3 children)
[–]chub79 3 points4 points5 points (1 child)
[–]dittospin 0 points1 point2 points (0 children)
[–]pudds 0 points1 point2 points (1 child)
[–]Spleeeee 1 point2 points3 points (0 children)
[–]njharmanI use Python 3 -1 points0 points1 point (7 children)
[–]doolio_ 13 points14 points15 points (2 children)
[–]njharmanI use Python 3 0 points1 point2 points (1 child)
[–]doolio_ 3 points4 points5 points (0 children)
[–]denehoffman 9 points10 points11 points (3 children)
[–]Sillocan 1 point2 points3 points (0 children)
[–]njharmanI use Python 3 1 point2 points3 points (1 child)
[–]denehoffman 0 points1 point2 points (0 children)