Skip to content

Conversation

@liamhuber
Copy link
Member

@liamhuber liamhuber commented Jul 22, 2025

Transformers map many:1 for i/o or o/i, and currently the hint for the 1 side of things is very generic. Here, we add the ability to specify a content type at construction:

import pyiron_workflow as pwf

n = pwf.api.inputs_to_list(3, "a", None, "c", content_type_hint=str | None)
print(n.outputs.list.type_hint)
>>> list[str | None]

try:    
    n.inputs.item_2 = 42
except TypeError:
    print("Nope, needs to be str | None")
>>> Nope, needs to be str | None

Closes #703

@ligerzero-ai, at the moment I think I will move away from inferring hints. The trouble is that sometimes we initialize with direct values (then type inference is easy), but sometimes we initialize with nodes or channels (which are also perfectly valid input arguments to the new node!) I might take a crack at it again later, but this makes the inference logic pretty hairy.

If you want to have the infer off by default, a nicer error would help a lot - like TypeHint might not be specific enough - specify the datatype in flag ...

I'm going to double-down on laziness and also not address that here. The error raised is actually being raised generically from trying to set invalid input values to an input channel, so there is no context that this channel was created as part of a inputs_to_list node or similar. The tail end of the error message already anyhow supplies a hint towards the type hinting:

Please check type hints, etc. /test_mod_dataclass/modify_to_rigid_keys_list.list.type_hint = <class 'list'>; /modify_dataclass_multi.entry_names.type_hint = list[str]

TODO:

  • inputs to dict (was just some hint propagation)
  • refactoring transform.py to condense away some abstract classes (got rid of all the intermediate classes -- Transform serves to group them all and change their draw colour, but each one handles its functionality independently. There is a smidgen of code repetition, but I think it's more readable now)

Signed-off-by: liamhuber <[email protected]>
Signed-off-by: liamhuber <[email protected]>
Signed-off-by: liamhuber <[email protected]>
Signed-off-by: liamhuber <[email protected]>
in inputs_to_list

Signed-off-by: liamhuber <[email protected]>
Signed-off-by: liamhuber <[email protected]>
Signed-off-by: liamhuber <[email protected]>
@github-actions
Copy link

Binder 👈 Launch a binder notebook on branch pyiron/pyiron_workflow/typed_transformers

@ligerzero-ai
Copy link

no problem - all good

@codecov
Copy link

codecov bot commented Jul 22, 2025

Codecov Report

Attention: Patch coverage is 99.00000% with 1 line in your changes missing coverage. Please review.

Project coverage is 91.87%. Comparing base (9592209) to head (379e55f).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
pyiron_workflow/nodes/transform.py 98.92% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #729      +/-   ##
==========================================
+ Coverage   91.79%   91.87%   +0.07%     
==========================================
  Files          34       35       +1     
  Lines        3730     3764      +34     
==========================================
+ Hits         3424     3458      +34     
  Misses        306      306              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

liamhuber added 10 commits July 22, 2025 16:05
Signed-off-by: liamhuber <[email protected]>
Signed-off-by: liamhuber <[email protected]>
Signed-off-by: liamhuber <[email protected]>
Directly onto Transformer

Signed-off-by: liamhuber <[email protected]>
And simplify the typing

Signed-off-by: liamhuber <[email protected]>
Signed-off-by: liamhuber <[email protected]>
@liamhuber liamhuber marked this pull request as ready for review July 22, 2025 23:56
@liamhuber liamhuber merged commit 2b486fa into main Jul 23, 2025
21 checks passed
@liamhuber liamhuber deleted the typed_transformers branch July 23, 2025 00:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Weird behaviour in typehinting/type return when using pwf.api.inputs_to*

3 participants