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

feat: make Signal and SignalInstance Generic, support static type validation of signal connections #304

Open
wants to merge 17 commits into
base: main
Choose a base branch
from

Conversation

tlambert03
Copy link
Member

@tlambert03 tlambert03 commented Apr 1, 2024

supports the ability to perform static type checking on signal connection signatures

class Thing:
    sig = Signal(int, str)

t = Thing()

@t.sig.connect
def cb1() -> None: ...  # OK
@t.sig.connect
def cb2(a0: int) -> None: ...  # OK
@t.sig.connect
def cb3(a0: int, a1: str) -> None: ...  # OK

@t.sig.connect
def cb5(a0: int, a1: str, a2: float) -> None: ...  # ERR: too many params
@t.sig.connect
def cb6(a0: str) -> None: ...  # ERR: wrong type for a0

Copy link

codecov bot commented Apr 1, 2024

Codecov Report

Attention: Patch coverage is 96.77419% with 1 line in your changes missing coverage. Please review.

Project coverage is 99.95%. Comparing base (019232e) to head (cdb2ec3).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
src/psygnal/_signal.py 96.15% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##              main     #304      +/-   ##
===========================================
- Coverage   100.00%   99.95%   -0.05%     
===========================================
  Files           21       21              
  Lines         2062     2089      +27     
===========================================
+ Hits          2062     2088      +26     
- Misses           0        1       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

codspeed-hq bot commented Apr 1, 2024

CodSpeed Performance Report

Merging #304 will degrade performances by 56.98%

Comparing tlambert03:generic-signal (cdb2ec3) with main (019232e)

Summary

⚡ 2 improvements
❌ 5 regressions
✅ 59 untouched benchmarks

🆕 1 new benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark main tlambert03:generic-signal Change
test_create_signal 68.8 µs 28.2 µs ×2.4
test_create_signal_instance 33.4 µs 77.6 µs -56.98%
test_dataclass_group_create[attrs] 536.8 µs 676.7 µs -20.68%
test_dataclass_group_create[dataclass] 523.1 µs 657.7 µs -20.47%
test_dataclass_group_create[msgspec] 544.9 µs 676 µs -19.39%
test_dataclass_group_create[pydantic] 541.2 µs 677.9 µs -20.17%
🆕 test_emit_fast N/A 21.7 µs N/A
test_emit_time[partial-2] 69 µs 61.6 µs +12.04%

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant