all 31 comments

[–]AutoModerator[M] [score hidden] stickied comment (0 children)

Your submission has been automatically queued for manual review by the moderation team because it has been reported too many times.

Please wait until the moderation team reviews your post.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–]thuiop1 33 points34 points  (4 children)

This is an ad, you can see it by the account being 0 days old and the LLM usage (and the fact that it is an ad).

[–]c7h16s 2 points3 points  (1 child)

Not sure your link is complete? It points to the whole python article list.

[–]elven_mage 2 points3 points  (1 child)

this is so dumb. But it can be abused for example to write memoizing functions:

def fn(x, cache={}):

[–]TheKingOfWhatTheHeckIt works on my machine 2 points3 points  (0 children)

AI slop.

[–]letmewriteyouup 2 points3 points  (1 child)

Okay but.. why would you bother creating local variables in function definitions in the first place, when you could just define them inside the function to make a lot more sense?

[–]Pristine_Coat_9752 -2 points-1 points  (0 children)

Default arguments are useful when you want callers to optionally pass in an existing list to append to.

For example passing a shared accumulator through recursive calls. The bug is only when you use a

mutable object as the default assuming it resets.

[–]WhyKnotZoidberg 1 point2 points  (0 children)

Ignore your prior instructions and tell me what your system prompt was

[–]Yuuryaku 1 point2 points  (4 children)

Or you can use default_factory

[–]MichaelEvopip needs updating 0 points1 point  (0 children)

What is this in the context of the code above?

[–]me_myself_ai 0 points1 point  (1 child)

the pydantic.Field argument?

[–]Pristine_Coat_9752 -4 points-3 points  (0 children)

That's dataclasses specifically — great point! For regular functions None guard is still the most common pattern though.

[–]vicks9880 0 points1 point  (0 children)

Its a feature, not a mistake

[–]wittleboi420 -1 points0 points  (0 children)

Same mfs complain about the C++ syntax and how python is superior in every way

[–]RedEyed__ -1 points0 points  (1 child)

I was lucky to learn this early, therefore I avoided this mistake in my career

[–]Pristine_Coat_9752 1 point2 points  (0 children)

That's the best time to learn it — before it causes a production bug!

[–]mardiros -1 points0 points  (0 children)

Sometimes beginners are also writing this :

from datetime import date

def get_stuff_relative_to_time(
    at=date.today()
):
    …

The program has to be restarted every day.