Urgent.News

What's breaking now, across hundreds of outlets.

Tech

A Partial Keyword Argument Can Be Overridden by Its Caller

A callable assembled with functools.partial can look like a fixed policy. Its saved keyword arguments are defaults for later calls: a caller can supply the same keyword with another value. A positional argument already supplied to the original function behaves differently when a later keyword tries to fill that position again. This exercise uses a label formatter and a list. It distinguishes call…

When a callable is assembled with functools.partial, it can appear to have fixed keyword arguments. These saved keyword arguments serve as defaults for subsequent calls. However, a caller can still override these saved keywords by providing a different value.

If a positional argument has already been supplied to the original function, a later keyword argument that attempts to fill that position will not be accepted. This behavior demonstrates that a partial object exposes a mutable keywords dictionary.

The examples provided do not implement an authorization check. The Python 3.12 reference documentation outlines the library behavior observed during testing. The tests cover four scenarios: saved keyword usage when omitted, call keyword overriding saved keyword, extension of the call with a new keyword, and the mutability of the keywords dictionary.

In the first test, a partial object with a saved prefix keyword is created. When calling the partial object with only the value argument, the saved prefix is used as expected.

The second test shows that a call keyword can override a saved keyword. By providing the prefix keyword with a different value during the call, the saved prefix is overridden.

The third test confirms that a saved positional argument is not treated as a keyword default. In this case, a partial object is created with a saved left positional argument. When calling the partial object with a different left value, a TypeError is raised, indicating that the saved positional argument is not a keyword default.

The fourth test verifies that the keywords dictionary remains mutable after being modified. A partial object is created with a saved prefix keyword. After modifying the saved prefix in the keywords dictionary, the modified value is used in subsequent calls to the partial object.

Finally, the last test demonstrates that a bound mutable argument is not copied when used with partial. A list is initialized as a mutable object, and the append method is used as a partial object. When calling the partial object with an argument, the original mutable list is used, and its contents are updated accordingly.

Rewritten by urgent.news; may contain errors — check the original.

Source: dev.to

Read the original at dev.to →

Report a problem with this story

More in Tech

Your input is wrong by ten minutes. Which of your outputs survive?

Most systems are built on the assumption that you know your inputs. Here is one where the primary input is routinely wrong, everybody knows it is wrong, and sixteen separate outputs are derived from…

  • Input birth time rounded to nearest five or ten minutes yields 16 divisional charts
  • 11.2 out of 16 divisional charts change with ±10 minute input error
  • Ascendant shifts ~1 degree every 4 minutes, minimal impact on Shashtiamsha

Self-host Agno AgentOS or HiveGate with Docker Compose

You have an Agno agent that works, and you want it running on your own machine or server, behind an HTTP API, with its data in your own database. The first questions are practical. Which containers?

  • AgentOS uses two containers: Postgres and API, with agnohq/pgvector:18
  • HiveGate requires JWT authentication and token management, unlike AgentOS

More from Wednesday 25 November →