Skip to content

fix: Better Singleton with Typed Bounded Functions#42

Merged
AttAditya merged 1 commit into
mainfrom
fix/singleton-autosig
Jun 1, 2026
Merged

fix: Better Singleton with Typed Bounded Functions#42
AttAditya merged 1 commit into
mainfrom
fix/singleton-autosig

Conversation

@AttAditya

@AttAditya AttAditya commented Jun 1, 2026

Copy link
Copy Markdown
Owner

LangEx 0.4.6

Release Summary

  • Update Type: Minor
  • Update Version: 0.4.5 -> 0.4.6
  • Breaking Changes: No
  • Backwards Compatibility: upto 0.4.5
  • Target Issue: None

Changelog

  • Refactor Singleton decorator to use ClassMeta and a wrapper object for cleaner instance handling.

    • Eliminated the need to store instance state in self.
    • Simplified attribute lookup and assignment via proxy methods.
    • Improved readability and future extensibility.
  • Extend FunctionMeta to mimic original function attributes for compatibility with decorators like autosig.

    • Copied __code__, __defaults__, __kwdefaults__, __annotations__, __doc__, __qualname__, and __name__.
    • Provides accurate function introspection after wrapping.
    • Prepares functions for automated signature enforcement.
  • Add autosig support on singleton methods, enabling type validation.

    • Introduced next_id_with_prefix with a string type annotation.
    • Updated tests to validate proper error handling and output.
    • Import ValidationError and autosig in tests for clearer semantics.

Updated Library Highlights

Singleton Decorator

from langex.classes.class_meta import ClassMeta

def Singleton(cls):
  instance = ClassMeta(cls).use_primitive()()
  class Wrapper():
    def __call__(self):
      return instance
    def __getattr__(self, name):
      return getattr(instance, name)
    def __setattr__(self, name, value):
      return setattr(instance, name, value)
  return Wrapper()

Autosig on Singleton Method

from langex.core.functions import autosig
from langex.core.errors import ValidationError

@singleton
class IdGenerator:
  def __init__(self):
    self.value = 0
  def next_id(self):
    self.value += 1
    return self.value
  @autosig
  def next_id_with_prefix(self, prefix: str) -> str:
    return f"{prefix}_{self.next_id()}"

Future Plans

  • Remove this section as there are no immediate expansion plans.

Notes

  • No additional notes at this time.

@github-actions

github-actions Bot commented Jun 1, 2026

Copy link
Copy Markdown

🔍 Generating PR summary using AI for commit 895370e57b3f79489caf8b6f488e1461afb0e85d...

@github-actions

github-actions Bot commented Jun 1, 2026

Copy link
Copy Markdown

✅ PR summary updated using AI for commit 895370e57b3f79489caf8b6f488e1461afb0e85d.

@github-actions

github-actions Bot commented Jun 1, 2026

Copy link
Copy Markdown

🏷️ Generating labels using AI for commit 895370e57b3f79489caf8b6f488e1461afb0e85d...

@github-actions github-actions Bot added BUG Observed unexpected behavior TESTS Related to code tests labels Jun 1, 2026
@github-actions

github-actions Bot commented Jun 1, 2026

Copy link
Copy Markdown

🏷️ Labels added: BUG,TESTS (commit 895370e57b3f79489caf8b6f488e1461afb0e85d)

@AttAditya
AttAditya merged commit ddd6739 into main Jun 1, 2026
3 checks passed
@AttAditya
AttAditya deleted the fix/singleton-autosig branch June 1, 2026 13:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

BUG Observed unexpected behavior TESTS Related to code tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant