Skip to content

Threaded Decorator Type-Safety #33

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 9 commits into from
Dec 24, 2023
Merged

Threaded Decorator Type-Safety #33

merged 9 commits into from
Dec 24, 2023

Conversation

caffeine-addictt
Copy link
Member

What type of PR is this? (check all applicable)

  • Refactor
  • Feature
  • Bug Fix
  • Optimization
  • Breaking Change
  • Documentation Update

Description

Made the use of threaded decorators type-safe by overriding the original function's signature with ParamSpec and TypeVar.

Related Tickets & Documents

QA Instructions, Screenshots, Recordings

Boilerplate code

import thread

@thread.threaded
def a(x: int):
  return 2 + x

a1 = a(3)
a2 = a1.result
a3 = a1.get_return_value()


@thread.threaded()
def b(x: int):
  return 2 + x

b1 = b(3)
b2 = b1.result
b3 = b1.get_return_value()


@thread.threaded()
def c(x: int):
  return 2 + x

c1 = c(3)
c2 = c1.result
c3 = c1.get_return_value()

Intellisense should type hint correctly

image
image
image
image

Added/updated tests?

We encourage you to keep the code coverage percentage at 80% and above.

  • Yes
  • No, and this is why: Untestable change
  • I need help with writing tests

Checklist

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.

@caffeine-addictt caffeine-addictt added the Type: Feature Suggest a new feature. label Dec 24, 2023
@caffeine-addictt caffeine-addictt self-assigned this Dec 24, 2023
@caffeine-addictt caffeine-addictt merged commit b4675ed into main Dec 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Feature Suggest a new feature.
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Type Safety on decorators
1 participant