Search⌘ K
AI Features

Keyword Args & Immutability

Explore how to use keyword arguments with __pragma__ directives in Transcrypt and understand the handling of immutable objects in a React front-end environment. This lesson helps you manage state updates and use techniques like copying immutable props for effective front-end development.

We'll cover the following...

Keyword arguments

By default, unpacking keyword arguments with **kwargs in a function does not work out of the box in Transcrypt. This is because it would lead to bloated code when it gets transpiled to JavaScript. Fortunately, Transcrypt provides us with a compiler directive that will selectively enable that feature for just when it’s needed. Here is a simple example:

Python 3.8
# __pragma__('kwargs')
def test_function(**kwargs):
for key, val in kwargs.items():
print(key, ":", val)
# __pragma__('nokwargs')

So, we basically just have to wrap our function that uses **kwargs in the __pragma__ compiler directives to turn it on, then turn it off again. Transcrypt will then make sure that the ...