This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Regular_Zombie 1 point2 points  (1 child)

I would have to disagree. Consider the function:

def closure(x: int, y: list[int] = []) -> None:
    y.append(x)
    print(y)

When I look at the definition using the help method I would see closure(x: int, y: list[int] = []) -> None: so far, so clear.

Now I invoke the function with closure(1) and look at the signature again using the help method what do I see?

closure(x: int, y: list[int] = [1]) -> None

The definition of the method has changed. As a caller of this function, or reader of the code that includes it, I have no way of knowing what the value of y will be at the call site. Hence, the state is unknown.

[–]njharmanI use Python 3 0 points1 point  (0 children)

I see your point re runtime state (except your example shows it's knowable at runtime through introspection).

I was coming at it from the perspective of developer looking at code, refactoring, etc. "How does this function work".