Properties are not always optional
gvanrossum opened this issue · 2 comments
Hey Stone team! We found an issue with the typing stub code generated for properties. I believe this block of code should be deleted:
stone/stone/backends/python_type_stubs.py
Lines 369 to 371 in e695746
The effect of this block is to always add Optional[]
around the return type of a property getter. (The logic looks backwards, but for nullable and void types there already is an Optional[]
.)
But if you look at the runtime code generated, you'll see that for a non-nullable default-less property, None
is never returned, it raises an exception if the value isn't set:
stone/stone/backends/python_types.py
Lines 625 to 634 in e695746
I will propose a PR to fix this. I have tested the PR in the Dropbox server repo, and it caused only two errors, and those look genuine.
CC: @ilevkivskyi
nit: should the second code example from line 609 to line 618?
Oh, you're right. Here's the code fragment I meant to link to:
stone/stone/backends/python_types.py
Lines 603 to 618 in e695746