-
-
Notifications
You must be signed in to change notification settings - Fork 0
feat: pydantic #236
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
feat: pydantic #236
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d989da5
feat: pydantic added.
zMynxx 8836ba0
feat: upgraded coverage.
zMynxx 1405430
feat: mypy fixes and typing.
zMynxx 9b44b3c
feat: mypy in checks.
zMynxx 52a3d2f
fix: typo.
zMynxx 1f53900
fix: typo.
zMynxx 1107410
chore: checks
zMynxx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| [mypy] | ||
| # Type checking configuration | ||
| python_version = 3.13 | ||
| show_error_codes = True | ||
| ignore_missing_imports = True | ||
|
|
||
| # Exclude test files | ||
| exclude = tests/ | ||
|
|
||
| # Exclude utility files that have complex typing issues | ||
| [mypy-aws_lambda_calculator.pricing_scraper] | ||
| ignore_errors = True | ||
|
|
||
| [mypy-aws_lambda_calculator.screenshotter] | ||
| ignore_errors = True |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| from pydantic import BaseModel, Field, model_validator | ||
| from typing import Literal | ||
|
|
||
|
|
||
| class CalculationRequest(BaseModel): | ||
| """Pydantic model for AWS Lambda cost calculation request parameters.""" | ||
|
|
||
| region: str = Field(default="us-east-1", description="AWS region for pricing") | ||
|
|
||
| architecture: Literal["x86", "arm64"] = Field( | ||
| default="x86", description="Lambda function architecture" | ||
| ) | ||
|
|
||
| number_of_requests: int = Field( | ||
| default=1000000, gt=0, description="Number of Lambda requests" | ||
| ) | ||
|
|
||
| request_unit: Literal[ | ||
| "per second", | ||
| "per minute", | ||
| "per hour", | ||
| "per day", | ||
| "per month", | ||
| "million per month", | ||
| ] = Field(default="per day", description="Unit for number of requests") | ||
|
|
||
| duration_of_each_request_in_ms: int = Field( | ||
| default=1500, gt=0, description="Duration of each request in milliseconds" | ||
| ) | ||
|
|
||
| memory: float = Field( | ||
| default=128, gt=0, description="Memory allocated to Lambda function" | ||
| ) | ||
|
|
||
| memory_unit: Literal["MB", "GB"] = Field( | ||
| default="MB", description="Unit for memory allocation" | ||
| ) | ||
|
|
||
| ephemeral_storage: float = Field( | ||
| default=512, gt=0, description="Ephemeral storage allocated to Lambda function" | ||
| ) | ||
|
|
||
| storage_unit: Literal["MB", "GB"] = Field( | ||
| default="MB", description="Unit for ephemeral storage" | ||
| ) | ||
|
|
||
| @model_validator(mode="after") | ||
| def validate_aws_lambda_limits(self) -> "CalculationRequest": | ||
| """Validate memory and ephemeral storage are within AWS Lambda limits.""" | ||
| # Validate memory | ||
| if self.memory_unit == "MB": | ||
| if self.memory < 128 or self.memory > 10240: | ||
| raise ValueError("Memory must be between 128 MB and 10,240 MB") | ||
| elif self.memory_unit == "GB": | ||
| if self.memory < 0.125 or self.memory > 10.24: | ||
| raise ValueError("Memory must be between 0.125 GB and 10.24 GB") | ||
|
|
||
| # Validate ephemeral storage | ||
| if self.storage_unit == "MB": | ||
| if self.ephemeral_storage < 512 or self.ephemeral_storage > 10240: | ||
| raise ValueError( | ||
| "Ephemeral storage must be between 512 MB and 10,240 MB" | ||
| ) | ||
| elif self.storage_unit == "GB": | ||
| if self.ephemeral_storage < 0.5 or self.ephemeral_storage > 10.24: | ||
| raise ValueError( | ||
| "Ephemeral storage must be between 0.5 GB and 10.24 GB" | ||
| ) | ||
|
|
||
| return self | ||
|
|
||
|
|
||
| class CalculationResult(BaseModel): | ||
| """Pydantic model for AWS Lambda cost calculation result.""" | ||
|
|
||
| total_cost: float = Field(description="Total monthly cost in USD") | ||
|
|
||
| calculation_steps: list[str] = Field( | ||
| description="Step-by-step calculation breakdown" | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check notice
Code scanning / CodeQL
Explicit returns mixed with implicit (fall through) returns Note
Copilot Autofix
AI 24 days ago
Copilot could not generate an autofix suggestion
Copilot could not generate an autofix suggestion for this alert. Try pushing a new commit or if the problem persists contact support.