Oct-31-2022, 08:07 PM
(This post was last modified: Oct-31-2022, 08:08 PM by deanhystad.)
Correct. An argument named "type" (or "print" or "list" or ...) will hide the same-named built-in function in the function scope. Does your function need to call type()? If you want a "type" argument and you want to call the "type" function, I suggest using "type_" as the argument name. Trying to hide the argument name by popping it from **kwargs is a lot of effort and confusion just to avoid a trailing "_". It is the kind of "cute" coding trick that is not going to win you any friends from people who might have to use or maintain this code. "Why doesn't "type" show up as an argument for that_function() in autocomplete?" Static analysis will also report it as an error, if you ever do that.
If you need to be cute, I find this less egregious. Terrible, but less terrible than what you want to do.
If you need to be cute, I find this less egregious. Terrible, but less terrible than what you want to do.
import builtins # <- Provides a clue that you are up to no good def my_func(type=None): print(type, builtins.type(type)) my_func(5) my_func("Hello")
Output:5 <class 'int'>
Hello <class 'str'>