Skip to content

Conversation

@joe4dev
Copy link
Member

@joe4dev joe4dev commented Jan 9, 2026

Motivation

Found small typing issues.

Changes

  • Introduced consistent typing for InitializationType
  • Fixed tuple typings
  • Fixed Docker platform typing using StrEnum Reverted due to Python 3.10 CLI incompatibility :(
  • Attempted to fix generator typings (e.g., Generator[ExecutionEnvironment, None, None]:). PyCharm suggested this typing, but then complains upon usage. ❓ What's the right typing here?

Related

Related to DRG-97

@joe4dev joe4dev added semver: patch Non-breaking changes which can be included in patch releases docs: skip Pull request does not require documentation changes notes: skip Pull request does not have to be mentioned in the release notes labels Jan 9, 2026
@github-actions
Copy link

github-actions bot commented Jan 9, 2026

Test Results - Preflight, Unit

23 046 tests  ±0   21 201 ✅ ±0   6m 6s ⏱️ -50s
     1 suites ±0    1 845 💤 ±0 
     1 files   ±0        0 ❌ ±0 

Results for commit 9b66c28. ± Comparison against base commit 0b2a5d1.

♻️ This comment has been updated with latest results.

@github-actions
Copy link

github-actions bot commented Jan 9, 2026

Test Results (amd64) - Acceptance

7 tests  ±0   5 ✅ ±0   2m 59s ⏱️ +5s
1 suites ±0   2 💤 ±0 
1 files   ±0   0 ❌ ±0 

Results for commit 9b66c28. ± Comparison against base commit 0b2a5d1.

♻️ This comment has been updated with latest results.

@github-actions
Copy link

github-actions bot commented Jan 9, 2026

Test Results (amd64) - Integration, Bootstrap

    5 files  ±0      5 suites  ±0   2h 37m 0s ⏱️ + 1m 8s
5 569 tests ±0  5 008 ✅ ±0  561 💤 ±0  0 ❌ ±0 
5 575 runs  ±0  5 008 ✅ ±0  567 💤 ±0  0 ❌ ±0 

Results for commit 9b66c28. ± Comparison against base commit 0b2a5d1.

♻️ This comment has been updated with latest results.

@github-actions
Copy link

github-actions bot commented Jan 9, 2026

LocalStack Community integration with Pro

    2 files  ±0      2 suites  ±0   1h 58m 35s ⏱️ + 1m 28s
5 162 tests ±0  4 764 ✅ ±0  398 💤 ±0  0 ❌ ±0 
5 164 runs  ±0  4 764 ✅ ±0  400 💤 ±0  0 ❌ ±0 

Results for commit 9b66c28. ± Comparison against base commit 0b2a5d1.

♻️ This comment has been updated with latest results.

@joe4dev joe4dev marked this pull request as ready for review January 10, 2026 10:54
def get_invocation_lease(
self, function: Function | None, function_version: FunctionVersion
) -> InitializationType:
) -> Generator[InitializationType, Any, None]:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think there's a bit of a conceptual mismatch here.

From the python typing.Generator docs:

If your generator will only yield values, set the SendType and ReturnType to None:

Your current signature implies the returned Generator accepts a value via the generator.send method. This allows a caller to "send" values into generator functions, resuming execution.

However, the contextmanager protocol never sends values into generators -- instead only ever relying on next() to start/resume execution.

So the type should actually be:

Suggested change
) -> Generator[InitializationType, Any, None]:
) -> Generator[InitializationType, None, None]:

Furthermore, we can simplify this type to an Iterator[YieldType] since the docs go on to suggest:

Alternatively, annotate your generator as having a return type of either Iterable[YieldType] or Iterator[YieldType]:

So since we only care about the YieldType (i.e InitializationType) we should simplify this typing to use the collections.abc.Iterator ABC:

Suggested change
) -> Generator[InitializationType, Any, None]:
) -> Iterator[InitializationType]:

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome 🙌 Thank you for sharing @gregfurman

That's easiest to read despite PyCharm not liking it. I went ahead and replaced this and the other occurrence for get_environment

Maybe, PyCharm doesn't implement the with usage typings correctly here, yielding a warning 🤷‍♂️
Screenshot 2026-01-12 at 12 39 28

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The IDE and AI generate unnecesarily complex or wrong stuff here:

  • IDE: Generator[Literal[InitializationType.provisioned_concurrency, InitializationType.on_demand], Any, None]
  • Gemini 3: Generator[InitializationType, Any, None]
    • You correctly pointed out that Any should be None because the method does not have a return type
    • Question I asked it: "What are the correct typings for localstack.services.lambda_.invocation.counting_service.CountingService.get_invocation_lease?"

import contextlib
import logging
from collections import defaultdict
from collections.abc import Generator
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: If we decide to go with my suggestion for Iterator this should be replaced:

Suggested change
from collections.abc import Generator
from collections.abc import Iterator

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for reminding to import from collections.abc and not the deprecated typings (first IDE suggestion)

@joe4dev joe4dev requested a review from gregfurman January 12, 2026 11:44
@joe4dev joe4dev merged commit 11f2c45 into main Jan 12, 2026
42 checks passed
@joe4dev joe4dev deleted the refine-lambda-typings branch January 12, 2026 13:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs: skip Pull request does not require documentation changes notes: skip Pull request does not have to be mentioned in the release notes semver: patch Non-breaking changes which can be included in patch releases

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants