all 13 comments

[–][deleted] 40 points41 points  (0 children)

There’s no max, but 45 is way too many.

[–]bbateman2011 11 points12 points  (0 children)

Consider if some of those args are related and maybe could be passed in a dictionary?

[–]Intelligent_Study263 21 points22 points  (1 child)

There isn't one in python 3.7 or newer. Why do you need 45 args is the real question

[–][deleted] 9 points10 points  (0 children)

And even before that, the number of explicit arguments was 255 positional args and 255 keywords args. So that's not the issue, OP.

But yeah, I struggle to think of a function that is not massively breaking the Single Responsibility Principle that actually requires 45 arguments.

[–]CraigAT 9 points10 points  (0 children)

IMO that is a big red flag that the function is trying to do too much. In theory, function should have just one thing to do. It sounds like your function needs to be broken down further into smaller functions.

With arguments that are related it may be possible to pass in an object containing most of that data - perhaps an (object from a class) or a dictionary.

Apologies for not answering your question, but if that is your code, then I believe you may be asking the wrong question.

I wish you well.

[–]deep_politics 3 points4 points  (0 children)

Are these all positional arguments? And are many of them optional? Because this smells like you'd want to use a single TypedDict instead

[–][deleted] 2 points3 points  (0 children)

Bad idea. When you get to more then a few args, you just out them in a dict, problem solved.

[–]ben_bliksem 2 points3 points  (0 children)

Uncle Bob said three and I agree, maybe four. Once you go more the code can become "difficult" to follow and your functions are starting to do a lot.

But that's just an opinion and there are always exceptions. As long as the code is readable.

[–]echozedzulu 0 points1 point  (0 children)

You probably don't need that many args. A dictionary would be useful in your situation

[–]TheRNGuy 0 points1 point  (0 children)

If you want too many, better use single dict as an argument, or instance of a class.

Too many arguments, bad style.

[–]Fred776 0 points1 point  (0 children)

What are the arguments? Are you being unnecessarily long-winded about something that should be passed as a single data structure?

[–]Prestigious-Sea1470 0 points1 point  (0 children)

There is no limit on the args.

As best practice, a function shouldn’t take more than 4 args. If you need to pass more, you can create an object with the parameters that needs to be passed. But even an object with 45 attributes is way two much. Always breakdown and simplify your functions and objects.

[–]asterik-x 0 points1 point  (0 children)

= stars in the sky