-
Notifications
You must be signed in to change notification settings - Fork 996
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
First stab at minimal mypy implementation #738
Conversation
@@ -739,7 +739,7 @@ def select(options: List[_T], name=None, list_append=False, recurse=False, skip_ | |||
assert not isinstance(value, RawFunction), "You cannot select between stateful functions in the current guidance implementation!" | |||
assert not isinstance(value, types.FunctionType), "Did you pass a function without calling it to select? You need to pass the results of a called guidance function to select." | |||
if isinstance(value, int) or isinstance(value, float): | |||
options[i] = str(value) | |||
options[i] = str(value) # type: ignore[assignment] |
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 didn't understand this, because options is type List[_T] but this is inserting a string.
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 may have gotten the type wrong when I was trying to figure it out. Something like Union[List[_T], str]
might be correct.
@@ -380,7 +382,7 @@ def __repr__(self, state_sets=None) -> str: | |||
rs += "•" | |||
else: | |||
assert False | |||
s += f"{rs:40} ({state.start}) {'nullable' if state.node.nullable else ''}\n" | |||
s += f"{rs:40} ({state.start}) {'nullable' if state.node.nullable else ''}\n" # type: ignore[attr-defined] |
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.
It thinks that node doesn't have a nullable. I couldn't find out what state was. Next person to touch this function should type it.
@@ -10,7 +10,7 @@ | |||
@guidance(stateless=True, dedent=False) | |||
def regex(lm, pattern): | |||
# find all of the brackets we'll need to negate later | |||
nots = re.findall('\[\^(.*?)\]', pattern) | |||
nots = re.findall(r'\[\^(.*?)\]', pattern) |
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.
This was resulting in an actual error
@@ -1,17 +1,19 @@ | |||
try: | |||
from IPython.display import clear_output, display, HTML | |||
ipython_is_imported = True |
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.
This is a much cleaner way to do dynamic import.
clear_output(wait=True) | ||
display(HTML(self._html())) | ||
else: | ||
pprint(self._state) |
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.
pprint is the best I could think of. Should fix #708
I don't think that's me. |
Thank you for starting on this. I've authorised this for running in GH Actions. |
@riedgar-ms can you understand why it's giving: TypeError: 'module' object is not callable mypy is passing and I didn't change anything like that |
guidance/py.typed
Outdated
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.
What's the purpose of this file?
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.
This indicates to people who are installing this library that it can be analyzed by mypy.
I'm not quite sure why that is happening. The magic that is supposed to make the module callable is: Line 16 in 03d2b97
but you haven't edited that file. Are you able to run the tests on your own machine? |
Do you have local testing instructions anywhere? |
I'm not sure they're written out. You'll need the python -m pytest -m "not (needs_credentials or use_gpu or server)" tests/ |
Ok so it does run on main and not in this branch, so it must be something in my pr. I'll try to fix it. |
@riedgar-ms ok fixed it. Importing |
I would not be averse to such a change (although perhaps not for this PR). Thoughts @Harsha-Nori ? |
Oh I edited the comment to not include the suggestion about the |
Codecov ReportAttention: Patch coverage is
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## main #738 +/- ##
==========================================
- Coverage 69.69% 65.55% -4.15%
==========================================
Files 54 54
Lines 4029 4038 +9
==========================================
- Hits 2808 2647 -161
- Misses 1221 1391 +170 ☔ View full report in Codecov by Sentry. |
I generally like of how simple/clean "import guidance" being used for the decorator looks, but I appreciate that it causes some complexity in the developer onboarding here. I could definitely be persuaded against it but agree that we should discuss it in a separate issue/PR in more detail. The mypy typing infrastructure looks great, and I appreciate the incremental approach you've taken here @ryanpeach! Happy to do a full review once the tests finish running (which it seems like they will). Thanks for the great contribution! |
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'm OK with this.... @Harsha-Nori ?
.github/workflows/qa_tests.yml
Outdated
python-version: 3.8 | ||
- name: Install mypy | ||
run: pip install mypy | ||
- uses: tsuyoshicho/action-mypy@v4 |
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.
Should this be producing a comment on the PR? Or does that only happen if there's an error?
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.
It should if there's an error, but I realize it's hard to test prior to release
Anyway you can just run the qa_tests to see if my latest commit fixes the last commits problem? |
I assume the reason you manually run workflows is some of them cost money? We should make it so some workflows run on approval/workflow_dispatch and others run on push. |
Cost is a reason; as is keeping secrets secret. There is some GH security setting we have on that means that external contributions need a member of the repo to approve before things run. |
Ok let me work on this at ryanpeach#1 since this custom action is behaving oddly |
…version will always be same as setup.py this way.
… --version before running its setup commands
@riedgar-ms ok now it works in my PR to my own repo. |
Ready. Also rebased so that it should have a linear history. |
Passed, except one got canceled somehow, resulting in a red X. |
Issue: #729 #257
This is a non-strict implementation of mypy, with cicd integrated.
After this is approved, we can either slowly move towards a strict implementation, or each PR can simply
choose how much they want/need to contribute to the typing system to help themselves understand the codebase.