# 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!
comments vs inline
Typing in Python has two versions:
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 doTypeVar
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!