Skip to content
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

quality_control: remove imports that were deprecated in Python 3.9 #8681

Merged
merged 1 commit into from
Nov 11, 2024

Conversation

SpecLad
Copy link
Contributor

@SpecLad SpecLad commented Nov 11, 2024

Motivation and context

This is a continuation of #8626.

How has this been tested?

Checklist

  • I submit my changes into the develop branch
  • [ ] I have created a changelog fragment
  • [ ] I have updated the documentation accordingly
  • [ ] I have added tests to cover my changes
  • [ ] I have linked related issues (see GitHub docs)
  • [ ] I have increased versions of npm packages if it is necessary
    (cvat-canvas,
    cvat-core,
    cvat-data and
    cvat-ui)

License

  • I submit my code changes under the same MIT License that covers the project.
    Feel free to contact the maintainers if that's a concern.

Summary by CodeRabbit

  • New Features

    • Enhanced type clarity for attributes in the QualityReport and AnnotationConflict classes.
    • Modernized type hinting style across various classes and methods for improved readability.
  • Bug Fixes

    • No functional changes or bug fixes were introduced; the updates focus solely on type annotations.

@SpecLad SpecLad requested a review from Marishka17 as a code owner November 11, 2024 15:17
Copy link
Contributor

coderabbitai bot commented Nov 11, 2024

Walkthrough

The changes in this pull request involve updates to type hints and import statements in the models.py and quality_reports.py files within the quality control module. Specifically, the import of Sequence has been changed from typing to collections.abc, and several attributes in the QualityReport and AnnotationConflict classes have been explicitly typed. Additionally, type hints across various methods and fields in quality_reports.py have been modernized from List and Dict to their built-in counterparts list and dict.

Changes

File Path Change Summary
cvat/apps/quality_control/models.py Changed import of Sequence from typing to collections.abc. Updated children, conflicts, and annotation_ids attributes to use Sequence type hints.
cvat/apps/quality_control/quality_reports.py Updated type hints from List and Dict to list and dict for various classes and methods, including _fields_dict, annotation_ids, frames, and conflicts.

Poem

In the land of code where rabbits play,
Types are updated in a modern way.
From lists to dicts, oh what a sight,
Hopping through changes, everything feels right!
With sequences clear, our paths are bright,
Let’s celebrate coding, from morning till night! 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between d315485 and fcdcbf4.

📒 Files selected for processing (2)
  • cvat/apps/quality_control/models.py (1 hunks)
  • cvat/apps/quality_control/quality_reports.py (36 hunks)
🔇 Additional comments (5)
cvat/apps/quality_control/models.py (2)

7-7: LGTM! Import changes align with Python 3.9+ standards

The change to import Sequence from collections.abc instead of typing follows PEP 585 and removes usage of deprecated imports.

Also applies to: 10-10


Line range hint 89-89: Verify Django model field type hints compatibility

The type hints added for Django model fields look correct, but let's verify they work well with Django's type system and ORM. These fields are likely populated through Django's related_name mechanism:

  • children through parent's related_name
  • conflicts through report's related_name
  • annotation_ids through conflict's related_name

Let's check if similar type hints are used elsewhere in the codebase:

Also applies to: 90-90, 102-102, 103-103, 157-157, 158-158

✅ Verification successful

Let me gather more information about Django's type hint usage in the codebase, particularly focusing on related fields and their type annotations.


Type hints are correctly used and consistent with Django patterns

The type hints using Sequence for Django model relations are appropriate and consistent with the codebase's typing patterns. Evidence:

  • Similar type hints are used in engine/models.py for Django relations (e.g., frames: models.manager.RelatedManager[ValidationFrame])
  • The codebase properly imports typing utilities (from collections.abc import Sequence)
  • Type hints are used for both regular fields and reverse relations
  • Sequence is a good choice as it's more generic than List and matches Django's lazy-loading behavior

The type hints will work well with Django's type system and ORM, as they follow established patterns in the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for similar Django model field type hints
rg -U "class.*\(models\.Model\):(\n|.)*?Sequence\[.*?\]" --type py

# Search for any typing-related imports in Django model files
rg "^from collections.abc import|^from typing import" $(rg -l "class.*\(models\.Model\)" --type py)

Length of output: 2069


Script:

#!/bin/bash
# Search for type hints on Django related fields
ast-grep --pattern 'class $CLASS(models.Model):
  $$$
  $_: $TYPE
  $$$'

# Look for any typing-related documentation or configuration
fd "typing|mypy" --type f --exec rg -l "django|models"

Length of output: 16084

cvat/apps/quality_control/quality_reports.py (3)

10-10: LGTM: Import from collections.abc is the correct approach

The change to import Sequence from collections.abc instead of typing aligns with Python 3.9's deprecation of these types in the typing module.


121-121: LGTM: Type hint modernization is correct

The changes consistently update type hints from List and Dict to their built-in counterparts list and dict, which is the recommended approach in modern Python. The type safety is maintained while using more idiomatic type hints.

Also applies to: 164-164, 180-180, 242-242, 414-414, 470-470, 485-485, 538-538, 541-541, 545-545


865-865: LGTM: Implementation changes are type hint updates only

The changes are purely type hint modernization, updating from List and Dict to list and dict. No functional changes have been made to the implementation.

Also applies to: 963-963, 998-998, 1145-1145, 1748-1748, 1760-1760, 2376-2376, 2388-2388, 2453-2453, 2460-2460, 2537-2537


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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 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.

Copy link

@SpecLad
Copy link
Contributor Author

SpecLad commented Nov 11, 2024

@zhiltsov-max Let me know if this conflicts with any patches you plan to merge soon; I can delay merging this patch and rebase it afterwards if necessary.

@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 87.50000% with 4 lines in your changes missing coverage. Please review.

Project coverage is 74.19%. Comparing base (d315485) to head (fcdcbf4).
Report is 3 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #8681      +/-   ##
===========================================
- Coverage    74.24%   74.19%   -0.05%     
===========================================
  Files          401      401              
  Lines        43502    43504       +2     
  Branches      3950     3950              
===========================================
- Hits         32296    32277      -19     
- Misses       11206    11227      +21     
Components Coverage Δ
cvat-ui 78.49% <ø> (-0.02%) ⬇️
cvat-server 70.51% <87.50%> (-0.07%) ⬇️

@SpecLad SpecLad merged commit 1e7ff33 into cvat-ai:develop Nov 11, 2024
34 checks passed
@SpecLad SpecLad deleted the deprecated-typing branch November 11, 2024 16:52
SpecLad added a commit to SpecLad/cvat that referenced this pull request Nov 26, 2024
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.

3 participants