Skip to content

feat(core): add functools.partial and lru_cache #396

@antonsynd

Description

@antonsynd

Summary

functools.partial and functools.lru_cache were deferred from stdlib Phase 2 because they require features not yet available in Sharpy:

  • partial(func, *args): Needs a runtime callable wrapper that captures partial arguments. Challenging with Sharpy's static type system — requires creating a generic wrapper or using Func<> delegation.
  • lru_cache(maxsize=128): Needs decorator argument support in the compiler. Currently decorators are recognized but decorator arguments are not fully supported.
  • cache: Alias for lru_cache(maxsize=None), blocked by same issue.

Current State

  • functools.reduce() and functools.cmp_to_key() are implemented and working
  • partial, lru_cache, cache are not implemented

Possible Approaches

  • partial: Could use object[] captured args with runtime dispatch, or generate specialized Func<> wrappers
  • lru_cache: Requires compiler support for @decorator(args) syntax generating wrapper code

Context

Deferred from stdlib Phase 2 plan.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions