Skip to content

add ty for type hinting#562

Merged
chrisaddy merged 8 commits intomasterfrom
introduce-ty
May 28, 2025
Merged

add ty for type hinting#562
chrisaddy merged 8 commits intomasterfrom
introduce-ty

Conversation

@chrisaddy
Copy link
Copy Markdown
Collaborator

@chrisaddy chrisaddy commented May 28, 2025

This pull request introduces several updates across configuration files, Python models, and dependencies to enhance functionality, improve type safety, and update tooling. Key changes include adding new dependencies, improving type annotations, and updating linting and testing configurations.

Configuration and Tooling Updates:

  • .mise.toml: Added uvx wrapper for vulture and ty check to improve linting and type-checking workflows. [1] [2]
  • pyproject.toml: Added new dependencies (flytekit, pulumi-docker-build, pulumi-gcp) and configured ty rules to ignore unresolved imports. [1] [2]

Type Annotations and Model Updates:

Codebase Maintenance:

  • infrastructure/project.py: Added a # ty: ignore[missing-argument] comment to suppress type-checking warnings for a lambda function.

Summary by CodeRabbit

  • New Features

    • Added new dependencies: flytekit, pulumi-docker-build, and pulumi-gcp.
  • Style

    • Improved formatting and added type-checking directives for resource argument assignments.
  • Chores

    • Updated type annotations to allow certain fields and parameters to accept None values.
    • Enhanced linting and type-checking commands for Python tasks.
    • Introduced configuration to ignore unresolved imports during type checking.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 28, 2025

Walkthrough

The updates introduce new dependencies and type-checking rules in the project configuration, adjust type annotations to allow None for certain fields and constructor arguments, and update task commands for linting and dead code detection. Additionally, a stylistic change is made to a lambda expression in the infrastructure code, adding a type-ignore directive.

Changes

File(s) Change Summary
.mise.toml Updated python:dead-code task to use uvx vulture; appended uvx ty check to python:lint.
application/datamanager/src/datamanager/config.py Changed api_key type to `str
application/positionmanager/src/positionmanager/clients.py Changed constructor argument types in AlpacaClient and DataClient to allow `str
infrastructure/project.py Reformatted lambda for IAMMember's member argument; added type-ignore comment.
pyproject.toml Added flytekit, pulumi-docker-build, pulumi-gcp dependencies; added type-check ignore rules.

Suggested labels

python, application

Poem

A rabbit hops through fields of code,
Where types may now be None,
New tools and checks upon the road,
With dependencies spun.
Linting stronger, tasks anew—
🐇 Cheers to changes, swift and true!


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5d0a80e and e9c324b.

📒 Files selected for processing (2)
  • application/datamanager/src/datamanager/config.py (1 hunks)
  • application/positionmanager/src/positionmanager/clients.py (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • application/datamanager/src/datamanager/config.py
  • application/positionmanager/src/positionmanager/clients.py
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@graphite-app
Copy link
Copy Markdown

graphite-app Bot commented May 28, 2025

Graphite Automations

"Assign author to pull request" took an action on this PR • (05/28/25)

1 assignee was added to this PR based on John Forstmeier's automation.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (1)
pyproject.toml (1)

68-69: Consider the implications of ignoring unresolved imports.

The unresolved-import = "ignore" configuration may hide legitimate import issues. While this can be helpful during development or when dealing with dynamic imports, it could mask real problems.

Consider being more specific about which imports to ignore, or document why this broad ignore rule is necessary. You might want to use more targeted ignores in the code instead:

[tool.ty.rules]
-unresolved-import = "ignore"
+# Consider removing this and using targeted # ty: ignore comments instead
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 748f753 and 0723e4c.

⛔ Files ignored due to path filters (1)
  • uv.lock is excluded by !**/*.lock
📒 Files selected for processing (5)
  • .mise.toml (2 hunks)
  • application/datamanager/src/datamanager/config.py (1 hunks)
  • application/positionmanager/src/positionmanager/clients.py (2 hunks)
  • infrastructure/project.py (1 hunks)
  • pyproject.toml (2 hunks)
🔇 Additional comments (5)
pyproject.toml (1)

7-10:

Details

✅ Verification successful

Verify new dependency versions and security.

The added dependencies support infrastructure and workflow management, which aligns with the project's needs. However, ensure these specific versions are current and free from known vulnerabilities.


🏁 Script executed:

#!/bin/bash
# Description: Check for the latest versions and security advisories for new dependencies

echo "Checking flytekit..."
curl -s https://pypi.org/pypi/flytekit/json | jq -r '.info.version'

echo "Checking pulumi-docker-build..."
curl -s https://pypi.org/pypi/pulumi-docker-build/json | jq -r '.info.version'

echo "Checking pulumi-gcp..."
curl -s https://pypi.org/pypi/pulumi-gcp/json | jq -r '.info.version'

# Check for security advisories
gh api graphql -f query='
{
  securityVulnerabilities(first: 10, ecosystem: PIP, package: "flytekit") {
    nodes {
      advisory { summary severity publishedAt }
      vulnerableVersionRange
      firstPatchedVersion { identifier }
    }
  }
}'

gh api graphql -f query='
{
  securityVulnerabilities(first: 10, ecosystem: PIP, package: "pulumi-docker-build") {
    nodes {
      advisory { summary severity publishedAt }
      vulnerableVersionRange
      firstPatchedVersion { identifier }
    }
  }
}'

gh api graphql -f query='
{
  securityVulnerabilities(first: 10, ecosystem: PIP, package: "pulumi-gcp") {
    nodes {
      advisory { summary severity publishedAt }
      vulnerableVersionRange
      firstPatchedVersion { identifier }
    }
  }
}'

Length of output: 1324


Dependencies are up-to-date and have no known vulnerabilities.

Verified on PyPI that:

  • flytekit 1.15.4 is the latest release
  • pulumi-docker-build 0.0.12 is the latest release
  • pulumi-gcp has moved to 8.32.1 (your constraint ≥8.32.0 covers it)

GitHub’s security advisories show no reported vulnerabilities for these packages. No further action required.

infrastructure/project.py (1)

57-59:

Details

✅ Verification successful

Investigate if the type ignore directive is necessary.

The # ty: ignore[missing-argument] suggests a potential typing issue with the IAMMember constructor or lambda function. While type ignores can be useful, it's better to address the root cause when possible.


🏁 Script executed:

#!/bin/bash
# Description: Check the IAMMember constructor signature and usage patterns

# Look for IAMMember class definition and constructor
ast-grep --pattern $'class IAMMember {
  $$$
  def __init__($$$) {
    $$$
  }
  $$$
}'

# Check for other IAMMember usages in the codebase
rg -A 10 -B 5 "IAMMember\(" 

# Look for similar patterns with member parameter
rg -A 5 -B 5 "member.*apply"

Length of output: 1294


Keep the # ty: ignore[missing-argument] here

The ignore suppresses a false-positive from Pyright/Pylance on Pulumi’s Output.apply signature (the type stubs declare extra parameters that aren’t needed in practice). No changes are required.

.mise.toml (2)

16-16: Good practice using uvx for tool execution.

Using uvx vulture instead of direct vulture is a good practice as it manages tool dependencies in isolation and ensures consistent tool versions across environments.


29-29: Type checking integration looks good.

Adding uvx ty check to the lint task properly integrates the type checking workflow. This works well with the [tool.ty.rules] configuration added in pyproject.toml.

application/datamanager/src/datamanager/config.py (1)

8-8: Type annotation improvement is correct.

Changing api_key: str to str | None accurately reflects that os.getenv("POLYGON_API_KEY") can return None when the environment variable is not set.

Comment thread application/datamanager/src/datamanager/config.py Outdated
Comment thread application/positionmanager/src/positionmanager/clients.py Outdated
Comment thread application/positionmanager/src/positionmanager/clients.py
chrisaddy and others added 2 commits May 28, 2025 15:52
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🔭 Outside diff range comments (1)
application/datamanager/src/datamanager/config.py (1)

20-22: ⚠️ Potential issue

Remove duplicate daily_bars_path computed field.

You have two @computed_field methods with the same name daily_bars_path. This will cause the second definition (lines 20-22) to override the first one (lines 14-18), losing the important None validation logic.

Remove the duplicate method:

-    @computed_field
-    def daily_bars_path(self) -> str:
-        return f"gs://{self.name}/equity/bars/"

Keep only the first implementation (lines 14-18) which properly handles the case when self.name is None.

🧰 Tools
🪛 Ruff (0.11.9)

21-21: Redefinition of unused daily_bars_path from line 15

(F811)

♻️ Duplicate comments (1)
application/positionmanager/src/positionmanager/clients.py (1)

63-63: Add default value for optional parameter.

The datamanager_base_url parameter is typed as str | None but lacks a default value, making it not truly optional.

-    def __init__(self, datamanager_base_url: str | None):
+    def __init__(self, datamanager_base_url: str | None = None):
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0723e4c and 5d0a80e.

⛔ Files ignored due to path filters (1)
  • uv.lock is excluded by !**/*.lock
📒 Files selected for processing (5)
  • .mise.toml (2 hunks)
  • application/datamanager/src/datamanager/config.py (1 hunks)
  • application/positionmanager/src/positionmanager/clients.py (2 hunks)
  • infrastructure/project.py (1 hunks)
  • pyproject.toml (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • infrastructure/project.py
  • .mise.toml
  • pyproject.toml
🧰 Additional context used
🪛 Ruff (0.11.9)
application/positionmanager/src/positionmanager/clients.py

15-16: SyntaxError: Expected ')', found newline


16-16: SyntaxError: Invalid annotated assignment target


17-17: SyntaxError: Invalid annotated assignment target


18-18: SyntaxError: Invalid annotated assignment target


19-19: SyntaxError: Invalid annotated assignment target


20-20: SyntaxError: Unexpected indentation


21-21: SyntaxError: unindent does not match any outer indentation level


21-21: SyntaxError: Expected a statement


21-21: SyntaxError: Expected a statement


21-21: SyntaxError: Invalid annotated assignment target


21-22: SyntaxError: Expected an expression

🔇 Additional comments (2)
application/datamanager/src/datamanager/config.py (2)

8-8: Good improvement to type safety.

The change from str to str | None correctly reflects that os.getenv() can return None when the environment variable is not set. This enhances type safety and makes the nullable nature explicit.


14-18: ⚠️ Potential issue

Missing name field in Bucket class.

The daily_bars_path computed field references self.name, but there's no name field defined in the Bucket class. This will cause an AttributeError at runtime.

Add the missing field to the Bucket class:

 class Bucket(BaseModel):
+    name: str | None = Field(default=os.getenv("DATA_BUCKET"))
+
     @computed_field
     def daily_bars_path(self) -> str:

Likely an incorrect or invalid review comment.

Comment thread application/positionmanager/src/positionmanager/clients.py Outdated
@chrisaddy chrisaddy merged commit dd352b8 into master May 28, 2025
5 checks passed
@chrisaddy chrisaddy deleted the introduce-ty branch May 28, 2025 21:20
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.

2 participants