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

Add type hints to openslide package #260

Merged
merged 15 commits into from
Oct 19, 2024
Merged

Commits on Oct 18, 2024

  1. add typing for main interface file

    Signed-off-by: Sam Maxwell <[email protected]>
    Signed-off-by: Benjamin Gilbert <[email protected]>
    sammaxwellxyz authored and bgilbert committed Oct 18, 2024
    Configuration menu
    Copy the full SHA
    f31c8b2 View commit details
    Browse the repository at this point in the history
  2. type the deepzoom generator

    Signed-off-by: Sam Maxwell <[email protected]>
    sammaxwellxyz authored and bgilbert committed Oct 18, 2024
    Configuration menu
    Copy the full SHA
    f4b8131 View commit details
    Browse the repository at this point in the history
  3. Minor type fixes

    Signed-off-by: Benjamin Gilbert <[email protected]>
    bgilbert committed Oct 18, 2024
    Configuration menu
    Copy the full SHA
    5032e23 View commit details
    Browse the repository at this point in the history
  4. Enable type checking for entire openslide package

    Signed-off-by: Benjamin Gilbert <[email protected]>
    bgilbert committed Oct 18, 2024
    Configuration menu
    Copy the full SHA
    a6c2f82 View commit details
    Browse the repository at this point in the history

Commits on Oct 19, 2024

  1. Return subclass from AbstractSlide.__enter__()

    AbstractSlide subclasses will always return their specific type from
    this method.  Ensure the type system knows this.
    
    Signed-off-by: Benjamin Gilbert <[email protected]>
    bgilbert committed Oct 19, 2024
    Configuration menu
    Copy the full SHA
    e52cb3a View commit details
    Browse the repository at this point in the history
  2. Disallow bytes in filename arguments

    bytes will not work in at least one case (the OpenSlide initializer), are
    not documented to work, and the type annotations are currently
    inconsistent about accepting it.  For now, forbid it everywhere for
    consistency.
    
    Signed-off-by: Benjamin Gilbert <[email protected]>
    bgilbert committed Oct 19, 2024
    Configuration menu
    Copy the full SHA
    87495ba View commit details
    Browse the repository at this point in the history
  3. Explicitly hint the possible open_slide() return types

    open_slide() can't return any possible AbstractSlide subclass, only the
    two that it's documented to return.  Make that explicit in the type hint.
    
    Signed-off-by: Benjamin Gilbert <[email protected]>
    bgilbert committed Oct 19, 2024
    Configuration menu
    Copy the full SHA
    8c26361 View commit details
    Browse the repository at this point in the history
  4. Loosen mapping type guarantees

    Avoid overcommitting to internal implementation details in the types being
    returned.  It's sufficient to say that the property and associated image
    maps implement Mapping.
    
    Signed-off-by: Benjamin Gilbert <[email protected]>
    bgilbert committed Oct 19, 2024
    Configuration menu
    Copy the full SHA
    076e96f View commit details
    Browse the repository at this point in the history
  5. Drop _OpenSlideCacheWrapper

    We don't want to encourage library users to duck-type a replacement for
    OpenSlideCache, since any replacement would inherently need to make
    assumptions about our implementation details.
    
    Signed-off-by: Benjamin Gilbert <[email protected]>
    bgilbert committed Oct 19, 2024
    Configuration menu
    Copy the full SHA
    dccce62 View commit details
    Browse the repository at this point in the history
  6. Explicitly check for closed ImageSlide

    When an operation is performed on a closed ImageSlide, we've historically
    raised an AttributeError upon dereferencing None.  Add proper checks so
    the type system understands what we're doing, raising ValueError as
    lowlevel does.  This is not an API change because it only affects invalid
    caller behavior.
    
    Signed-off-by: Benjamin Gilbert <[email protected]>
    bgilbert committed Oct 19, 2024
    Configuration menu
    Copy the full SHA
    cfd1663 View commit details
    Browse the repository at this point in the history
  7. deepzoom: revert unrolling of _get_tile_info()

    We don't need to avoid generator expressions to keep the type checker
    happy; we can just assert that the resulting tuples have the correct
    length.  This lets us avoid carrying redundant unrolled code.
    
    Signed-off-by: Benjamin Gilbert <[email protected]>
    bgilbert committed Oct 19, 2024
    Configuration menu
    Copy the full SHA
    f24c1dd View commit details
    Browse the repository at this point in the history
  8. deepzoom: fix level_dimensions type hint

    level_dimensions is always a tuple of 2-tuples.  Prove this to the type
    checker.
    
    Signed-off-by: Benjamin Gilbert <[email protected]>
    bgilbert committed Oct 19, 2024
    Configuration menu
    Copy the full SHA
    0d675d6 View commit details
    Browse the repository at this point in the history
  9. Revert unrolling of ImageSlide.read_region()

    Keep the type checker happy by asserting the correct tuple lengths rather
    than unrolling generator expressions.
    
    Signed-off-by: Benjamin Gilbert <[email protected]>
    bgilbert committed Oct 19, 2024
    Configuration menu
    Copy the full SHA
    981684b View commit details
    Browse the repository at this point in the history
  10. Drop redundant return type hint

    __init__() methods don't need a return type hint unless they take no
    arguments.
    
    Signed-off-by: Benjamin Gilbert <[email protected]>
    bgilbert committed Oct 19, 2024
    Configuration menu
    Copy the full SHA
    f1d02fc View commit details
    Browse the repository at this point in the history
  11. Narrow some ImageSlide property types

    ImageSlide is hardcoded to a single level, and the level_count property
    and get_best_level_for_downsample() return types already reflect this.
    Reduce the level_dimensions() and level_downsamples() return types to
    1-tuples.  In the latter case we can't reduce to a Literal because literal
    floats are disallowed.
    
    Signed-off-by: Benjamin Gilbert <[email protected]>
    bgilbert committed Oct 19, 2024
    Configuration menu
    Copy the full SHA
    0efc25b View commit details
    Browse the repository at this point in the history