Skip to content

Commit

Permalink
Fix Python version compatibility issues
Browse files Browse the repository at this point in the history
* Use Typings for older Python version
* Convert TypedDict into dataclass
  • Loading branch information
joe4dev committed Mar 15, 2023
1 parent fe4e219 commit f249eb4
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
7 changes: 4 additions & 3 deletions localstack/utils/container_utils/container_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from abc import ABCMeta, abstractmethod
from enum import Enum, unique
from pathlib import Path
from typing import Dict, List, NamedTuple, Optional, Tuple, TypedDict, Union
from typing import Dict, List, NamedTuple, Optional, Tuple, Union

from localstack.utils.no_exit_argument_parser import NoExitArgumentParser

Expand Down Expand Up @@ -105,7 +105,8 @@ class DockerPlatform(str):
linux_arm64 = "linux/arm64"


class Ulimit(TypedDict, total=False):
@dataclasses.dataclass
class Ulimit:
"""The ``ulimit`` settings for the container.
See https://www.tutorialspoint.com/setting-ulimit-values-on-docker-containers
"""
Expand Down Expand Up @@ -1070,7 +1071,7 @@ def parse_additional_flags(

if args.ulimits:
ulimits = ulimits if ulimits is not None else []
ulimits_dict = {ul["name"]: ul for ul in ulimits}
ulimits_dict = {ul.name: ul for ul in ulimits}
for ulimit in args.ulimits:
name, _, rhs = ulimit.partition("=")
soft, _, hard = rhs.partition(":")
Expand Down
4 changes: 2 additions & 2 deletions localstack/utils/container_utils/docker_sdk_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ def create_container(
if ulimits:
kwargs["ulimits"] = [
docker.types.Ulimit(
name=ulimit["name"], soft=ulimit["soft_limit"], hard=ulimit["hard_limit"]
name=ulimit.name, soft=ulimit.soft_limit, hard=ulimit.hard_limit
)
for ulimit in ulimits
]
Expand Down Expand Up @@ -637,7 +637,7 @@ def run_container(
if ulimits:
kwargs["ulimits"] = [
docker.types.Ulimit(
name=ulimit["name"], soft=ulimit["soft_limit"], hard=ulimit["hard_limit"]
name=ulimit.name, soft=ulimit.soft_limit, hard=ulimit.hard_limit
)
for ulimit in ulimits
]
Expand Down
4 changes: 2 additions & 2 deletions localstack/utils/no_exit_argument_parser.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import argparse
import logging
from typing import NoReturn
from typing import NoReturn, Optional

LOG = logging.getLogger(__name__)

Expand All @@ -10,7 +10,7 @@
# Limitations of error cases: https://stackoverflow.com/a/67891066/6875981
# Subclassing workaround example: https://stackoverflow.com/a/59072378/6875981
class NoExitArgumentParser(argparse.ArgumentParser):
def exit(self, status: int = ..., message: str | None = ...) -> NoReturn:
def exit(self, status: int = ..., message: Optional[str] = ...) -> NoReturn:
LOG.warning(f"Error in argument parser but preventing exit: {message}")

def error(self, message: str) -> NoReturn:
Expand Down

0 comments on commit f249eb4

Please sign in to comment.