Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

Type hints & ChatGPT #16

Closed
nedtwigg opened this issue Feb 25, 2024 · 1 comment
Closed

Type hints & ChatGPT #16

nedtwigg opened this issue Feb 25, 2024 · 1 comment

Comments

@nedtwigg
Copy link
Member

comments vs inline

Typing in Python has two versions:

# compiles in all versions of Python
def trim(self):  # type: () -> 'Slice'

# only compiles in Python 3.5+
def trim(self) -> 'Slice':

We should use the second version - put the types inline, not in the comments. Looks like ChatGPT does this sometimes and not others. If it doesn't do it, make sure to ask it to try again and put the types in the function signature, not in the comments. If you find any useful prompts, share them here!

generics pre-PEP695 and post-PEP695

ChatGPT claims to know about PEP 695, but it forgets parts of it. See this example chat.

If the Kotlin code you are converting doesn't have any generics <T>, then you don't need to worry about this. But if it does, make sure you're using the latest syntax. We shouldn't need to do TypeVar stuff.

Even if you give ChatGPT the example at the beginning, it still gets it wrong. But if you point out the mistake it seems to be able to fix it. Example.

It looks like we might have better luck correcting ChatGPT's misunderstanding of PEP695 by hand. If you learn anything useful about this problem, share it here!

@nedtwigg
Copy link
Member Author

nedtwigg commented Mar 7, 2024

We're doing a good job with these.

@nedtwigg nedtwigg closed this as completed Mar 7, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant