-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Annotator types and docs: MyPy, consistent 'optional', small tidy-ups #1448
Conversation
* Previously sv.Color.RED would be seen as having type 'classproperty' * Setting the type info during construvtion passes it to the return type * Previously unhandled case where the class was missing is now explicitly checked for * Broke down the inheritance from 'property', as it was marking the result as 'classproperty' instead of e.g. Color, but only until type was provided (but without mypy confusion).
* No longer means 'has default value'. Removed where it meant that. * `Optional[datatype]` is now used instead of `datatype, optional` * Fixed a handful of incorrect type annotations
* Because we're generating docs from type annotations of function signatures, I can't find any other way to tell mypy that scene is np.ndarray
Testing checklist:
|
1d42bea
to
176fef1
Compare
|
81b4461
to
28e2f1a
Compare
|
Hi @onuralpszr , I've had a look at this, and I'd like you to remove your commits for now. The PR is mostly focused on annotators typing, and is already past the limits of how much should be contained in a single PR. I see the isort is immediately active, yet if some of the changes need a separate install, it'd likely sit idle as dead code until an indeterminate time in the future, which I don't want. |
28e2f1a
to
8f480ea
Compare
@LinasKo I backup my changes and I will move to another PR so we can merge mypy/isort formatting changes. Is that for work for you ? |
Yep, happy with that! |
@SkalskiP, I've addressed the requests, except for |
Description
MyPy was showing many issues in the
keypoints/annotators.py
andannotators/core.py
, so I cleaned it all up.Where the issues branched into other files, I likewise mopped it up. Here's a Loom. I strongly suggest reviewing one commit at-a-time.
Lastly, there are a few minuscule miscellaneous fixes.
Fixes:
np.array
tonp.ndarray
.Color.X
andColorPalette.X
in red, as it would see it as having typeclassproperty
. Changed it so it correctly seesColor
andColorPalette
.Optional[dtype]
if and only if they can beNone
.ImageType
wouldn't be seen asnp.ndarray
, as we type-annotate it asImageType
. I added assertions, which are the easiest way to tell mypy which one it is.sv.
.sv.KeyPoints
holds things of shape(N, 2)
, where it's actually(N, M, 2)
.Type of change
Please delete options that are not relevant.
How has this change been tested, please provide a testcase or example of how you tested the change?
Tested locally.
Colab: https://colab.research.google.com/drive/1UjRYth4NUfAsvQiz5-CfyRJ9zbXxj2i-?usp=sharing
Any specific deployment considerations
Many docstrings affected in a small way - have a quick look at type signatures, etc.
Docs