Skip to content
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

Dedent fixes for Python 3.12 #959

Merged
merged 10 commits into from
Jul 25, 2024
Merged

Dedent fixes for Python 3.12 #959

merged 10 commits into from
Jul 25, 2024

Conversation

Harsha-Nori
Copy link
Collaborator

@Harsha-Nori Harsha-Nori commented Jul 21, 2024

Aiming to fix #942

This should handle general use cases across Python versions, but further fixes are probably still needed for:

  • closure functions
  • nested f-strings (with arbitary nesting now possible in python 3.12 thanks to the new python parser improvements 😵‍💫)

I think these are both esoteric enough that we can kick the can down the road, but I'll keep thinking about it.

@mmoskal

@Harsha-Nori
Copy link
Collaborator Author

Harsha-Nori commented Jul 21, 2024

Also tag @riedgar-ms -- I may have put the tests in the wrong place, I saw "test_call_embeddings" inside of "test_model" which feels spiritually similar to the dedent semantics, but I'm really not sure where the right place is in the new framework. Happy to move these anywhere really

@riedgar-ms
Copy link
Collaborator

Looks like a reasonable location to me.

@hudson-ai
Copy link
Collaborator

Nice @Harsha-Nori! The solution is also a lot more readable than what was there before.

Regarding location, I think it's fine where it is, but I'd consider making a new file test_decorator.py or something of that sort in tests/unit/. If we later want to add some tests about inferring stateful/statelessness, etc. I think that we'd want to put those in there too.

source = " \n".join(
lines
) # TODO: this does not quite work because new_code_obj is now the __outer__closure_wrap() function...could be fixed with work...
# lines = source.split("\n")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can these commented blocks (in the tests as well) be deleted before merge, please?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Is it OK if we leave them in? The logic here is annoyingly tricky and while it's not feature complete yet, will be important to replicate when we extend the decorator to nested function definitions

@hudson-ai
Copy link
Collaborator

@riedgar-ms @Harsha-Nori any objections to merging this?

@Harsha-Nori
Copy link
Collaborator Author

Thanks for approving @hudson-ai and @riedgar-ms!

@Harsha-Nori Harsha-Nori merged commit 563371a into main Jul 25, 2024
110 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

dedent=True doesn't work in python 3.12
3 participants