Skip to content

Static evaluation of activators#696

Merged
Tishka17 merged 11 commits intodevelopfrom
feature/static_eval
Apr 3, 2026
Merged

Static evaluation of activators#696
Tishka17 merged 11 commits intodevelopfrom
feature/static_eval

Conversation

@Tishka17
Copy link
Copy Markdown
Member

@Tishka17 Tishka17 commented Mar 24, 2026

/closes #642

@Stefanqn
Copy link
Copy Markdown

def is_zero(value: int) -> bool:
    return value == 0
def fallback() -> str:
    return "a"
def needs_float(value: float) -> str:
    return str(value)

def test_surprise():
    provider = Provider(scope=Scope.APP)
    provider.provide(lambda: 1, provides=int)
    provider.activate(is_zero, Marker("ZERO")) # false
    provider.provide(fallback, provides=str)
    provider.provide(needs_float, provides=str, when=Marker("ZERO"))
    container = make_container(provider)

@Tishka17
Copy link
Copy Markdown
Member Author

@Stefanqn Static evaluation has limitations. I do not think calling arbitrary factories is safe at the moment of graph building. I will describe this in doc

@Stefanqn
Copy link
Copy Markdown

how about runtime fallback in this case? #701

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 3, 2026

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  src/dishka
  async_container.py 359-365
  container.py
  container_objects.py 24
  exceptions.py 44-45
  registry.py 218, 277-283
  src/dishka/code_tools
  code_builder.py 243, 251
  factory_compiler.py 144
  src/dishka/dependency_source
  activator.py 16
  src/dishka/graph_builder
  activation.py 61-63, 103, 117-118, 122, 134
  builder.py
  validator.py
  src/dishka/provider
  make_alias.py 40
  make_decorator.py
  provider.py
Project Total  

This report was generated by python-coverage-comment-action

@Tishka17 Tishka17 marked this pull request as ready for review April 3, 2026 12:03
@Tishka17 Tishka17 changed the title Some static evaluation logic Static evaluation of activators Apr 3, 2026
@Tishka17 Tishka17 force-pushed the feature/static_eval branch from 9711dd9 to d39be67 Compare April 3, 2026 12:43
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Apr 3, 2026

@Tishka17 Tishka17 merged commit c69248d into develop Apr 3, 2026
11 checks passed
@Tishka17 Tishka17 deleted the feature/static_eval branch April 3, 2026 13:02
@Tishka17 Tishka17 restored the feature/static_eval branch April 3, 2026 13:03
@Tishka17 Tishka17 deleted the feature/static_eval branch April 3, 2026 13:03
@Tishka17 Tishka17 mentioned this pull request Apr 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Static evaluation of activators

3 participants