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

Enhance typing with Self to support subclassing for multiple Python versions #1174

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mghotz
Copy link

@mghotz mghotz commented May 27, 2024

…ersions

Pull Request Checklist

Thank you for taking the time to improve Arrow! Before submitting your pull request, please check all appropriate boxes:

  • 🧪 Added tests for changed code.
  • 🛠️ All tests pass when run locally (run tox or make test to find out!).
  • 🧹 All linting checks pass when run locally (run tox -e lint or make lint to find out!).
  • 📚 Updated documentation for changed code.
  • ⏩ Code is up-to-date with the master branch.

If you have any questions about your code changes or any of the points above, please submit your questions along with the pull request and we will try our best to help!

Description of Changes

This PR enhances type hints in the Arrow library by using Self to support subclassing, ensuring compatibility with both Python 3.11 and earlier versions. The following changes were made:

Conditional Import: Imported Self from typing_extensions for Python versions below 3.11.
Updated Method Signatures: Modified methods in the Arrow class to return Self.
Type Casting: Used cast to handle type hinting where necessary.

Testing:
All existing tests were run and passed successfully, ensuring no breaking changes were introduced.

Issue:
Fixes Issue #1168.

Please review and merge this PR to improve the code's robustness and maintainability.

Copy link
Member

@jadchaar jadchaar left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution. Added a comment.

I also approved the workflow for a test run.

if sys.version_info >= (3, 11):
from typing import Self
else:
from typing_extensions import Self
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this be added to requirements for 3.11 and below?

https://github.com/arrow-py/arrow/tree/master/requirements

Copy link
Member

@jadchaar jadchaar Jun 23, 2024

Choose a reason for hiding this comment

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

A recent PR was merged to remove typing extensions for 3.8 and below. Mind rebasing this CR against the change and updating the requirements.txt to only pull it in for 3.9 and 3.10

reference PR - #1176

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.

Use typing.Self to support subclassing
2 participants