Skip to content

Fix TypeError when calling decorated methods with positional arguments#93

Merged
ludoo merged 2 commits into
masterfrom
ludo/issue-92
Jun 29, 2026
Merged

Fix TypeError when calling decorated methods with positional arguments#93
ludoo merged 2 commits into
masterfrom
ludo/issue-92

Conversation

@ludoo

@ludoo ludoo commented Jun 29, 2026

Copy link
Copy Markdown
Collaborator

Description

Calling decorated methods (such as output()) with positional arguments resulted in a TypeError (e.g., TypeError: TerraformTest._cache.<locals>.cache() takes 1 positional argument but 2 were given). This occurred because the _cache decorator's wrapper was defined to only accept self and **kwargs.

This PR fixes the issue by updating the decorator to:

  1. Accept both *args and **kwargs.
  2. Use inspect.signature to dynamically bind the arguments to the target function's signature. This ensures positional arguments are correctly mapped to their parameter names.
  3. Remove the self argument from the bound arguments before hashing to prevent the object's memory address from invalidating the cache.
  4. Maintain the early short-circuit when caching is disabled globally.

Tests

  • Added test_output_positional_arg to test/test_cache.py to verify that calling output() with positional arguments works correctly when caching is enabled.

Related Issues

ludoo added 2 commits March 31, 2026 08:06
The _cache decorator's wrapper was defined as cache(self, **kwargs),
which failed with a TypeError when decorated methods (like output())
were called with positional arguments.

We now use inspect.signature to bind the arguments, allowing both
positional and keyword arguments to be handled correctly while
preserving cache key generation.

Also added a regression test to test_cache.py and bumped the version
to 1.8.8.
@ludoo ludoo merged commit f8c79b4 into master Jun 29, 2026
12 checks passed
@ludoo ludoo deleted the ludo/issue-92 branch June 29, 2026 13: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.

TypeError when passing an unnamed argument to output

1 participant