Skip to content

Add bound types throughout layers and Ops - #599

Merged
svlandeg merged 79 commits into
explosion:developfrom
richardpaulhudson:feature/mypy-fixes
May 9, 2022
Merged

svlandeg merged 79 commits into
explosion:developfrom
richardpaulhudson:feature/mypy-fixes

Conversation

@richardpaulhudson

@richardpaulhudson richardpaulhudson commented Feb 24, 2022 •

Copy link
Copy Markdown
Contributor
  • Make it possible to declare layer model types e.g. Model[A, K] where the model supports types Model[Union[A, B, C], Union[K, L, M]]. This relies on bound type variables as defined in PEP484.

    This should hopefully make Thinc typing more developer-friendly and also increase the effectiveness of the Mypy Thinc plugin checking the validity of model chains, because it allows the specification of the concrete types being used in a given situation.

    Note that most of the type the documented type remains the same: covariant types are defined and used in the context of individual modules.

  • Support Mypy version 0.942 and Pydantic version 1.9.0.

  • Correct the documented type for some functions where it did not reflect the functionality supported by the code.

  • Cross-check the documentation with the code with respect to typing.

Despite the size of this PR, it changes virtually no running code: almost all the changes are to type definitions.

Btw I have now noticed #566 and this PR seems to have covered everything that is changed there.

Comment thread thinc/layers/embed.py Resolved
Comment thread thinc/layers/hashembed.py Resolved
Comment thread thinc/backends/ops.py Resolved
Comment thread thinc/layers/chain.py Resolved
Comment thread thinc/layers/dropout.py Resolved
Comment thread thinc/layers/uniqued.py Resolved
Comment thread thinc/layers/with_array.py Resolved
Comment thread thinc/layers/with_array.py Resolved
Comment thread thinc/types.py Resolved
@richardpaulhudson
richardpaulhudson marked this pull request as ready for review February 24, 2022 18:32
@svlandeg
svlandeg self-requested a review February 25, 2022 09:15
Comment thread thinc/layers/with_flatten.py Outdated
@@ -1,34 +1,34 @@
from typing import Tuple, Callable, Sequence, Any, List, TypeVar
from typing import Tuple, Callable, Sequence, Any, List, TypeVar, Optional

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've remodelled this along the lines of e.g. with_array; is that correct?

@svlandeg svlandeg left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another batch of reviews - I'll pause for a bit so we can decide/iterate on the ListXd thing from my last comment first.

Comment thread thinc/layers/chain.py Resolved
Comment thread thinc/layers/concatenate.py Resolved
Comment thread thinc/layers/list2ragged.py Resolved
Comment thread website/docs/api-layers.md Resolved
Comment thread website/docs/api-layers.md Resolved
Comment thread thinc/layers/list2ragged.py Resolved

@svlandeg svlandeg left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It feels like we're close to wrapping this one up! Added some more review comments.

Comment thread requirements.txt Resolved
Comment thread thinc/layers/residual.py Resolved
Comment thread thinc/layers/with_array.py Resolved
Comment thread thinc/layers/with_array.py Resolved
Comment thread thinc/layers/with_padded.py Resolved
Comment thread thinc/layers/with_ragged.py Resolved
Comment thread thinc/layers/with_ragged.py Resolved
Comment thread website/docs/api-layers.md Resolved
Comment thread website/docs/api-layers.md Resolved
Comment thread website/docs/api-layers.md Resolved
@svlandeg

Copy link
Copy Markdown
Contributor

Before we'd merge this in, we'd also need to re-test spacy against the current version in this PR.

Comment thread requirements.txt Resolved
@richardpaulhudson
richardpaulhudson changed the base branch from master to develop May 3, 2022 12:18
Comment thread thinc/backends/ops.py Resolved
Comment thread thinc/backends/ops.py Resolved
@svlandeg
svlandeg self-requested a review May 4, 2022 09:52
Comment thread thinc/backends/ops.py Resolved

@svlandeg svlandeg left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been quite the epic PR! I'm really happy that the Thinc types have gotten so much love and attention and are now in much better shape. Thanks for following through on this PR to the bitter end, Richard! 😁

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

Labels

enhancement Feature requests and improvements feat / types Type hints and type checking

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants