this post was submitted on 26 Feb 2025
24 points (100.0% liked)

Python

6723 readers
1 users here now

Welcome to the Python community on the programming.dev Lemmy instance!

๐Ÿ“… Events

PastNovember 2023

October 2023

July 2023

August 2023

September 2023

๐Ÿ Python project:
๐Ÿ’“ Python Community:
โœจ Python Ecosystem:
๐ŸŒŒ Fediverse
Communities
Projects
Feeds

founded 2 years ago
MODERATORS
 
class Node:
    def __init__(self, edges = set()):
        self.edges = edges


def main():
    foo = Node()
    bar = Node()
    quz = Node()

    foo.edges.add(bar)
    bar.edges.add(foo)

    assert(foo is not bar) # assertion succeeds
    assert(foo is not quz) # assertion succeeds
    assert(bar is not quz) # assertion succeeds
    assert(len(quz.edges) == 0) # assertion fails??


main()

spoilerMutable default values are shared across objects. The set in this case.

you are viewing a single comment's thread
view the rest of the comments
[โ€“] [email protected] 2 points 4 days ago* (last edited 4 days ago) (1 children)

What do you mean by trivial? I am not necessarily the most experienced coder, but it does a great job yelling at me to keep methods short and simple.

I'd suggest taking five minutes whenever and look up the ruff ruleset to see if it would be helpful for you.

Also maybe because I don't know how to use pylint in vs code, but the only semi useful thing it catches for me is if my venv doesn't have a library the code imports.

Edit: For example, Ruff has caught this bug (mutable argument defaults) in my code before.

[โ€“] FizzyOrange 1 points 4 days ago

it does a great job yelling at me to keep methods short and simple

Yes style things like that are what I would consider trivial. I also think those are actively bad lints. Yes methods should be short in general, but making it a hard enforced limit means you end up getting sidetracked by refactoring when you only wanted to add one line to a method.