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: build typed kwargs dicts #225

Merged
merged 8 commits into from
Sep 27, 2023
Merged

feat: build typed kwargs dicts #225

merged 8 commits into from
Sep 27, 2023

Conversation

tlambert03
Copy link
Owner

@tlambert03 tlambert03 commented Sep 27, 2023

This PR autogenerates TypeDicts classes corresponding to each OME object. For example, for ome.Channel, it would create:

class ChannelDict(TypedDict, total=False):
    light_source_settings: LightSourceSettingsDict | None
    detector_settings: DetectorSettingsDict | None
    filter_set_ref: FilterSetRefDict | None
    annotation_refs: list[AnnotationRefDict]
    light_path: LightPathDict | None
    id: str
    name: str | None
    samples_per_pixel: int | None
    illumination_type: ome.Channel_IlluminationType | str | None
    pinhole_size: float | None
    pinhole_size_unit: ome.UnitsLength | str
    acquisition_mode: ome.Channel_AcquisitionMode | str | None
    contrast_method: ome.Channel_ContrastMethod | str | None
    excitation_wavelength: float | None
    excitation_wavelength_unit: ome.UnitsLength | str
    emission_wavelength: float | None
    emission_wavelength_unit: ome.UnitsLength | str
    fluor: str | None
    nd_filter: float | None
    pockel_cell_setting: int | None
    color: ome.Color | str

they can be used for any functions that want to accept any of these kwargs, while retaining all of the type hints and IDE autocompletion. https://peps.python.org/pep-0692/

from typing import Unpack
def make_channel(**channel_kwargs: Unpack[ChannelDict]):
    return Channel(**channel_kwargs)

(I was starting to do this manually in #219 ... so this can be used there)

@codecov
Copy link

codecov bot commented Sep 27, 2023

Codecov Report

Merging #225 (26800ec) into main (a75d5f8) will increase coverage by 0.27%.
The diff coverage is 95.00%.

@@            Coverage Diff             @@
##             main     #225      +/-   ##
==========================================
+ Coverage   86.11%   86.38%   +0.27%     
==========================================
  Files          26       26              
  Lines        1217     1256      +39     
==========================================
+ Hits         1048     1085      +37     
- Misses        169      171       +2     
Files Coverage Δ
src/ome_types/model/__init__.py 100.00% <ø> (ø)
src/ome_autogen/main.py 97.72% <95.00%> (-2.28%) ⬇️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@codspeed-hq
Copy link

codspeed-hq bot commented Sep 27, 2023

CodSpeed Performance Report

Merging #225 will not alter performance

Comparing typed_dicts (26800ec) with main (a75d5f8)

Summary

✅ 9 untouched benchmarks

@tlambert03 tlambert03 enabled auto-merge (squash) September 27, 2023 12:42
@tlambert03 tlambert03 merged commit 06aa129 into main Sep 27, 2023
33 checks passed
@tlambert03 tlambert03 deleted the typed_dicts branch September 27, 2023 12:48
@tlambert03 tlambert03 added the enhancement New feature or request label Nov 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant