-
Notifications
You must be signed in to change notification settings - Fork 180
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
Typing #260
base: main
Are you sure you want to change the base?
Typing #260
Conversation
DCO signed off ✔️All commits have been signed off. You have certified to the terms of the Developer Certificate of Origin, version 1.1. In particular, you certify that this contribution has not been developed using information obtained under a non-disclosure agreement or other license terms that forbid you from contributing it under the GNU Lesser General Public License, version 2.1. |
Thanks for the PR! #243 is currently waiting for me to review it. I have a few other things to finish first, but it's on my list. mypy for ≥ 3.8 sounds good; that's what we've been using elsewhere. Ideally we'd type lowlevel too, but I'm not sure yet how much of a pain that will be. I know @jaharkes was also working on this. |
c0d19c3
to
0b6e742
Compare
Just fixed the tests, and remembered I also updated some pieces which previously output tuples to lists as their size was dynamic. I imagine this could be a problem and a technically a breaking change for those expecting tuples. |
openslide/deepzoom.py
Outdated
self._l_dimensions = [ | ||
( | ||
int(math.ceil(l_size[0] * size_scale[0])), | ||
int(math.ceil(l_size[1] * size_scale[1])), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've changed the zip pattern in a few places to directly construct the 2-element tuples so that the type checker knows it's a 2-element tuple.
Some initial comments:
Also cc @jaharkes for review. |
Also, if we use |
Not only that, but we could also use It looks like PEP 649 has opted for a third approach, neither classic annotations nor string-typed annotations, starting in Python 3.13. As I read the backward-compatibility section, annotated objects under PEP 649 will still have slightly different semantics if |
sure thing, apologies I assumed that was precommit
happy to use future
I think there was but may have just been a different battle with the type checker. I'll take a proper look at making the changes soon. Cheers |
043d2c8
to
3b621bd
Compare
@@ -438,14 +463,16 @@ def read_region(self, location, level, size): | |||
]: # "< 0" not a typo | |||
# Crop size is greater than zero in both dimensions. | |||
# PIL thinks the bottom right is the first *excluded* pixel | |||
crop = self._image.crop(image_topleft + [d + 1 for d in image_bottomright]) | |||
tile_offset = tuple(il - l for il, l in zip(image_topleft, location)) | |||
crop = self._image.crop( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
crop expects a 4-tuple rather than an n-tuple
min(self._z_t_downsample, z_lim - self._z_t_downsample * t) + z_tl + z_br | ||
for t, z_lim, z_tl, z_br in zip( | ||
t_location, self._z_dimensions[dz_level], z_overlap_tl, z_overlap_br | ||
z_size = ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the changes over the next few lines are to allow for the returned tuples to be 2-tuple rather than n-tuples where appropriate to fit with other calls e.g read_region
hey @bgilbert, suggestions applied and pushed.
|
6f4b6e0
to
01bf0b1
Compare
I've pushed #277 to require |
Signed-off-by: Sam Maxwell <sam@groundtruthlabs.com>
Signed-off-by: Sam Maxwell <sam@groundtruthlabs.com>
Rebased again to pick up more CI changes. |
Hey folks,
An attempt to address #157
I've typed the main interface and the deepzoom file, with ignoring type hints for the harder-to-type lowlevel file.
I think I could get there for lowlevel as well but would this suffice in the meantime?
Would have a few conflicts with #243, is that still active?
I've strict typed against 3.8 as per the mypy settings in pyproject.toml. Opted for mypy as that's the tool I'm familiar wth