How many args? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How many args?

This __build_class__ function needs some amount of arguments, but it doesn’t tell me how much it needs. It just says that there aren’t enough arguments. How many arguments does this thing need? https://sololearn.com/compiler-playground/c7Ngiqy8N3Od/?ref=app

27th Dec 2023, 7:08 PM
Annihilate
Annihilate - avatar
6 Answers
+ 3
It's an internal function that you would not normally modify. Just let it do it's own thing... you could do print(help(__build_class__)) to see what parameters it expects.
28th Dec 2023, 12:40 AM
Bob_Li
Bob_Li - avatar
+ 2
"Whenever you define a class, the function __build_class__ is called behind the scenes. __build_class__ is passed the class code (which is actually, suprisingly, a function) and the class name as arguments." https://sethdandridge.com/blog/defining-a-custom-class-constructor-in-JUMP_LINK__&&__python__&&__JUMP_LINK
27th Dec 2023, 7:16 PM
Lisa
Lisa - avatar
+ 2
Bob_Li , Good idea. It's sparse but more than I found on python.org. I think the docstring has typos: an extra s and an unwanted line feed. I'm guessing *bases is a tuple of 0 or more parent classes. / means parameters to the left are positional. help(__build_class__) # (print not needed) Output: Help on built-in function __build_class__ in module builtins: __build_class s__(...) __build_class__(func, name, /, *bases, [metaclass], **kwds) -> class Internal helper function used by the class statement.
28th Dec 2023, 5:58 AM
Rain
Rain - avatar
0
New Game , I only found one instance of "__build_class__" on python.org. https://peps.python.org/pep-0520/#changes
27th Dec 2023, 7:36 PM
Rain
Rain - avatar
0
Rain I can’t think of a way you would use this function because I don’t know what a metaclass is.
28th Dec 2023, 2:37 PM
Annihilate
Annihilate - avatar
0
New Game , Let's find out. These results are python.org pages that mention metaclass. https://duckduckgo.com/?q=site%3Apython.org%20metaclass
28th Dec 2023, 3:37 PM
Rain
Rain - avatar