Skip to content
This repository has been archived by the owner on Jul 3, 2023. It is now read-only.

Handle TypeVar types and enables most common generics support #94

Merged
merged 4 commits into from
Mar 23, 2022

Conversation

skrawcz
Copy link
Collaborator

@skrawcz skrawcz commented Mar 22, 2022

High level:

Changes

  • Refactors code to do type checks. This could look nicer, but it gets the job done. Unit tests don't break.
  • With the refactor I added support for generics. Tests added for this. There are edge cases I did not handle. E.g. didn't check TypedDicts.

Testing

  1. Added unit tests.
  2. Will see what CI tests break and see if I need to iterate.

Notes

Checklist

  • PR has an informative and human-readable title
  • Changes are limited to a single goal (no scope creep)
  • Code can be automatically merged (no conflicts)
  • Code follows the standards laid out in the
  • Passes all existing automated tests
  • Any change in functionality is tested
  • New functions are documented (with a description, list of inputs, and expected output)
  • Placeholder code is flagged / future todos are captured in comments
  • Project documentation has been updated (including the "Unreleased" section of the CHANGELOG)
  • Reviewers requested with the Reviewers tool ➡️

Testing checklist

Python

  • python 3.6
  • python 3.7

@skrawcz skrawcz marked this pull request as ready for review March 22, 2022 22:50
@skrawcz skrawcz requested a review from elijahbenizzy March 22, 2022 22:50
tests/test_graph.py Show resolved Hide resolved
tests/test_graph.py Show resolved Hide resolved
tests/test_graph.py Outdated Show resolved Hide resolved
@skrawcz skrawcz force-pushed the fix_subclass_check branch 3 times, most recently from 19aba9d to c4b6d8e Compare March 23, 2022 19:23
skrawcz added 3 commits March 23, 2022 12:59
We were not doing a great job ensuring that the issubclass check would not break.
So this changes that, and adds more use of the typing_inspect module. We'll have
to test this for compatibility to ensure things work with 3.6.

So I specifically created a dedicated function to encapsulate this type checking logic.

To handle generics, I did a very basic approximation that should work for most use cases.
E.g. list vs typing.List, or typing.Dict vs typing.Mapping.

In terms of precedence, the param_type is the input parameter type annotated on the function,
and the requested_param_type is coming from the output of an upstream function. Thus, the
param_type should be the super type if there is one, not the other way around.
Doing a runtime check to see if the input matches a typing.TypeVar
seems non trivial. So punting on this for now -- will likely have to
push this through to the other adapters, but waiting for impetus to
do so. This should enable #91 to work as intended.
Since github doesn't support git:// anymore.
@skrawcz skrawcz force-pushed the fix_subclass_check branch from c4b6d8e to f48cdab Compare March 23, 2022 19:59
To test that unit tests at least pass on 3.8 and 3.9 python.
With typing and typing_inspect there could be slight behavioral
differences.
@skrawcz skrawcz merged commit e2ad136 into main Mar 23, 2022
@skrawcz skrawcz deleted the fix_subclass_check branch March 23, 2022 22:51
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support typing.TypeVar annotations
2 participants