dss-extensions / dss-extensions/AltDSS-Python

Better mechanism to control SetterFlags

Offen
#3 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
enhancement
Vorherrschende Sprache
Python
Sterne
19
Forks
2
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

Currently this is an advanced feature, and users need to leave the comfort of the Python properties, using instead the setter methods in order to pass both a value and the flags.

Some context, from the tests:

```python

alt.Clear()
ls = alt.LoadShape.new('test_shape')
with pt.raises(DSSException):
ls.PMult = [1.0, 2.0, 3.0]

ls._set_PMult([1.0, 2.0, 3.0], SetterFlags.ImplicitSizes)
assert tuple(ls.PMult) == (1.0, 2.0, 3.0)

ls.end_edit()

```

Some possible alternatives:

- Use a context manager in Python to keep the flags used in a block, use these flags on each Python function (when passing to the C API) and reset them later. This could be combined with the `Edit` context manager later.

```python

with alt.with_setter_flags(SetterFlags.ImplicitSizes):
ls = alt.LoadShape.new('test_shape')
ls.PMult = [1.0, 2.0, 3.0]
assert tuple(ls.PMult) == (1.0, 2.0, 3.0)
ls.end_edit()

```

- Introduce a pair of API functions to control some default flags, expose it as a property. For this, we wouldn't need to change much of the Python code, but would require consuming the default flags on the engine:

```python
alt.DefaultSetterFlags = SetterFlags.ImplicitSizes
#...
ls = alt.LoadShape.new('test_shape')
ls.PMult = [1.0, 2.0, 3.0]
assert tuple(ls.PMult) == (1.0, 2.0, 3.0)
ls.end_edit()
```

Other examples include using `SetterFlags.AvoidFullRecalc` to minimize Yprim and SystemY changes for loads and generators. This is valid for both individual and batch operations.

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.