Skip to content

gh-132661: Implement PEP 750 #132662

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

Open
wants to merge 95 commits into
base: main
Choose a base branch
from
Open

Conversation

lysnikolaou
Copy link
Member

@lysnikolaou lysnikolaou commented Apr 17, 2025

PEP 750 implementation! πŸŽ‰

Let's make sure as many people as possible take a look at this, since it's touching many areas that I've not worked on before.


πŸ“š Documentation preview πŸ“š: https://cpython-previews--132662.org.readthedocs.build/

lysnikolaou and others added 30 commits October 18, 2024 17:41
* Rename expr to expression, conv to conversion
* Move templatelib under string lib
* Add strings lib to LIBSUBDIRS
* Update type of Template/TemplateIter/Interpolation
Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>
@lysnikolaou
Copy link
Member Author

I might be missing it (since the PR is rather big), but are there any pickle-related tests?

No, there aren't. Good idea to add some pickle-related tests as well! I'll have a look, but if someone else more knowledgeable around pickle beats me to it, that'd be great, too.

Copy link
Member

@AA-Turner AA-Turner left a comment

Choose a reason for hiding this comment

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

Looks good to me overall!

I'm happy to help review/contribute to the documentation for t-strings in a follow-up, let me know what would be most helpful.

A

@hugovk
Copy link
Member

hugovk commented Apr 23, 2025

Please also run the buildbots before merge.

They're currently a bit too red, but let's not make them more red: https://buildbot.python.org/#/release_status

@lysnikolaou lysnikolaou added the πŸ”¨ test-with-buildbots Test PR w/ buildbots; report in status section label Apr 23, 2025
@bedevere-bot

This comment was marked as resolved.

@bedevere-bot bedevere-bot removed the πŸ”¨ test-with-buildbots Test PR w/ buildbots; report in status section label Apr 23, 2025
@sobolevn
Copy link
Member

@lysnikolaou I think it would be good enough to test something like:

user = 'test'
for template in (
    t'',
    t"No values", 
    t'With inter {user}', 
    t'With ! {user!r}',
    t'With format {1 / 0.3:.2f}',
):
    for proto in range(pickle.HIGHEST_PROTOCOL + 1):
        with self.subTest(proto=proto, template=template):
            pickled = pickle.dumps(template, protocol=proto)
            unpickled = pickle.loads(pickled)

            self.assertEqual(unpickled.values, template.values)
            # ...

@sobolevn
Copy link
Member

I created #132831 for the buildbot failure.

@lysnikolaou
Copy link
Member Author

I think it would be good enough to test something like:

@sobolevn Where would you put this test? test_pickle somewhere? Would you be able to open a PR on my fork maybe?

@AA-Turner
Copy link
Member

I would also add tests for pickling instantiated classes (in test_string/test_templatelib.py).

@sobolevn
Copy link
Member

Would you be able to open a PR on my fork maybe?

Sure, working on it :)

Copy link
Member

@ZeroIntensity ZeroIntensity left a comment

Choose a reason for hiding this comment

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

A few last-minute comments about the object code.

@sobolevn
Copy link
Member

sobolevn commented Apr 23, 2025

I've also noticed that t''.__name__ and .__qualname__ are not supported. Also fixing this now :)

@AA-Turner
Copy link
Member

AA-Turner commented Apr 23, 2025

I've also noticed that t''.__name__ and .__qualname__ are not supported. Also fixing this now :)

This is expected, no? type(t'').__qualname__ == 'Template', but instances don't have names/qualnames. See e.g. ''.__name__ (which does not exist).

@sobolevn
Copy link
Member

@lysnikolaou here's my PR: lysnikolaou#75

Copy link
Member

@pablogsal pablogsal left a comment

Choose a reason for hiding this comment

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

Parser and grammar LGTM, will do another pass later this week if the PR is still open.

Fantastic work @lysnikolaou 🀘

@lysnikolaou
Copy link
Member Author

@markshannon @brandtbucher If you could take another look at the bytecode/compiler changes after the first round of feedback, that'd be great!

Copy link
Member

@ZeroIntensity ZeroIntensity left a comment

Choose a reason for hiding this comment

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

C code for the objects look good to me!

Copy link
Member

@sobolevn sobolevn left a comment

Choose a reason for hiding this comment

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

I also don't have any other objections :)

@lysnikolaou lysnikolaou added the πŸ”¨ test-with-buildbots Test PR w/ buildbots; report in status section label Apr 24, 2025
@bedevere-bot
Copy link

πŸ€– New build scheduled with the buildbot fleet by @lysnikolaou for commit 8468e10 πŸ€–

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F132662%2Fmerge

If you want to schedule another build, you need to add the πŸ”¨ test-with-buildbots label again.

@bedevere-bot bedevere-bot removed the πŸ”¨ test-with-buildbots Test PR w/ buildbots; report in status section label Apr 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.