Skip to content

Comments

Refactor Producer to leverage Type directly and allow direct Artifact instantiation#263

Merged
JacobHayes merged 2 commits intogoldenfrom
only-require-type-in-producer
Aug 3, 2022
Merged

Refactor Producer to leverage Type directly and allow direct Artifact instantiation#263
JacobHayes merged 2 commits intogoldenfrom
only-require-type-in-producer

Conversation

@JacobHayes
Copy link
Member

@JacobHayes JacobHayes commented Aug 3, 2022

Description

This refactors Producer to operate primarily against a Type rather than requiring a strict Artifact subclass (with a nested Type). The Type is derived from the parameter type annotations, by one of the following mechanisms:

  • inferring from the type hint (via python_type_system) (int)
  • using a Type instance embedded in an Annotated type hint (Annotated[int, Int64()])
  • using a Artifact class with a type default set embedded in an Annotated type hint (Annotated[int, MyArtifact])

Relaxing the requirement for Artifact subclass improves simple cases of Producer and Graph creation significantly and allows direct Artifact instantiation. As requested in #260, this simple example now works as expected:

from arti import Graph, producer

@producer()
def increment(numbers: list[int], by: int) -> list[int]:
    return [n + by for n in numbers]

with Graph(name="Demo") as g:
    g.artifacts.step, g.artifacts.numbers = 5, [1, 2, 3]
    g.artifacts.incremented = increment(numbers=g.artifacts.numbers, by=g.artifacts.step)

if __name__ == "__main__":
    g.build()
    print(g.read(g.artifacts.numbers, annotation=list[int]))
    print(g.read(g.artifacts.incremented, annotation=list[int]))

, yielding:

[1, 2, 3]
[6, 7, 8]

Resolves #260 and supersedes #259 (pickling now works fine w/o the dynamic classes).

Type of change

  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
    • Artifact.for_literal and Artifact.from_type have been removed
      • these were likely only used internally (via Artifact.cast).
    • Most of the pseudo-private Producer._*_ class vars have been replaced

How Has This Been Tested?

Tests have been updated and added to maintain coverage.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in upstream modules

@codecov-commenter
Copy link

codecov-commenter commented Aug 3, 2022

Codecov Report

Merging #263 (ee8aafa) into golden (a797f45) will increase coverage by 0.15%.
The diff coverage is 100.00%.

@@             Coverage Diff             @@
##           golden      #263      +/-   ##
===========================================
+ Coverage   99.84%   100.00%   +0.15%     
===========================================
  Files          42        42              
  Lines        2573      2578       +5     
  Branches      528       525       -3     
===========================================
+ Hits         2569      2578       +9     
+ Misses          4         0       -4     
Impacted Files Coverage Δ
src/arti/artifacts/__init__.py 100.00% <100.00%> (ø)
src/arti/executors/local.py 100.00% <100.00%> (ø)
src/arti/internal/models.py 100.00% <100.00%> (ø)
src/arti/producers/__init__.py 100.00% <100.00%> (ø)
src/arti/storage/__init__.py 100.00% <0.00%> (+1.53%) ⬆️
src/arti/formats/__init__.py 100.00% <0.00%> (+10.52%) ⬆️

📣 Codecov can now indicate which changes are the most critical in Pull Requests. Learn more

@JacobHayes JacobHayes merged commit 56d2896 into golden Aug 3, 2022
@JacobHayes JacobHayes deleted the only-require-type-in-producer branch August 3, 2022 21:47
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.

Support Producer validation with Types instead of (only) Artifacts

2 participants