Skip to content

Refine imports for type hints in Bybit #2149

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 1 commit into from
Dec 30, 2024

Conversation

sunlei
Copy link
Collaborator

@sunlei sunlei commented Dec 29, 2024

Pull Request

Refine imports for type hints in Bybit.

Type of change

Delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)

Copy link

codspeed-hq bot commented Dec 29, 2024

CodSpeed Performance Report

Merging #2149 will improve performances by 26.3%

Comparing sunlei/bybit-refine-imports (0514414) with develop (7392f06)

Summary

⚡ 1 improvements
✅ 51 untouched benchmarks

Benchmarks breakdown

Benchmark develop sunlei/bybit-refine-imports Change
test_order_denied_to_dict 42.3 µs 33.5 µs +26.3%

Copy link
Member

@cjdsellers cjdsellers left a comment

Choose a reason for hiding this comment

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

Are we using TYPE_CHECKING for performance reasons here?
I'd be interested to know the improvements if you have any before-after figures.

@sunlei
Copy link
Collaborator Author

sunlei commented Dec 30, 2024

@cjdsellers

I haven’t conducted performance tests for this specific scenario, but theoretically, it should be beneficial:

  • Isolate type-checking code.
  • Avoid unnecessary runtime imports.
  • Reduce the likelihood of circular references.

@cjdsellers
Copy link
Member

Sure, happy to merge - but thoughts are:

  • We haven't experienced any circular import issues for Bybit, that I know of.
  • Departs from the standard import patterns in most other Python modules.
  • Could be considered boilerplate unless a strong reason for it?

A reason in favor is the potential runtime performance improvement, would be interesting to know because it could inform heading this way for other modules too.

@cjdsellers cjdsellers merged commit a27923f into develop Dec 30, 2024
16 checks passed
@cjdsellers cjdsellers deleted the sunlei/bybit-refine-imports branch December 30, 2024 06:01
@sunlei
Copy link
Collaborator Author

sunlei commented Dec 30, 2024

@cjdsellers

Thank you!

  • Bybit previously encountered a circular reference issue in one of its PRs, which I resolved using TYPE_CHECKING.
  • I randomly checked two projects, PyTorch and Flask, and found that TYPE_CHECKING is used quite extensively.
  • In my own projects, TYPE_CHECKING often serves as boilerplate code.

For further reference:

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