Why do some `system` functions take keyword args and some don't?

Question in the title. E.g. system.dataset.sort doesn't take keyword args, but most do. Just wondering the reason most do but some don't? I like providing keyword args since it both:

  • makes it easier to read later on, especially if you're using a function you don't normally use
  • increases chances of backwards compatibility in case function arg definitions change (e.g. new args are added into existing arg indices) - this one should probably very rarely happen, but it's a possibility

You mean :

system.gui.transform(component=event.source, [...])
vs
system.dataset.sort(event.source.data, [...])

You're asking why you can't explicitly say:

system.dataset.sort(dataset=event.source.data, [...])?

1 Like

Correct

Pure chance on whomever originally implemented the function, until IA made it an internal best practice to support them. Most of the newer stuff supports them.

3 Likes

Yeah. On our side, implementing with keyword args takes slightly more effort and means slightly more complicated unit testing. It's definitely my preference for all first party functions, though.

3 Likes

I only use them when there's a mix of required and optional parameters, and even then sparingly.

They're a bit of a footgun in some cases, and can lead to mistakes and confusion like this if you don't name every parameter in your calls and instead fall back to the implicit ordering.

3 Likes

Ah just came across this as well. Will this be a feature or at least removed from the documentation if we can not use it?

Code works if i do not have the key word "naturalOrdering":

sortedDataSet = system.dataset.sort(updatedDataset, 0, naturalOrdering=True)

error:

com.inductiveautomation.ignition.common.script.JythonExecException
Traceback (most recent call last):
  File "<function:runAction>", line 6, in runAction
  File "<module:screen.tools>", line 1203, in getTagAddDataSetHeadersValuesToTag
TypeError: sort(): takes no keyword arguments

	caused by org.python.core.PyException
Traceback (most recent call last):
  File "<function:runAction>", line 6, in runAction
  File "<module:screen.tools>", line 1203, in getTagAddDataSetHeadersValuesToTag
TypeError: sort(): takes no keyword arguments


Ignition v8.1.36 (b2024010211)
Java: Azul Systems, Inc. 17.0.8

You can use it. You just cannot use a keyword to supply it. If you look carefully at the docs, you will see ascending and naturalOrdering together in a single set of brackets. That tells me they are a pair, supply neither or both, but not just one.

When keyword arguments are supported, the docs say so.

1 Like

Ohhh ok, I did not realize ignition made us do that. I was looking at it like python functions where we do not have to call them all was my mistake. That makes sense hank you!