Potential pyright --createstub
bug
#6399
Replies: 5 comments 12 replies
-
No, this isn't a bug. If you do not provide a return type annotation for a function or method, pyright will infer its type from the function's body — specifically, from the The I'm curious why you're creating a stub library for this code. Stubs are used as stand-ins for distributed libraries that lack type information, but this doesn't look like a library. If you're the author of this code, you should add type annotations directly to the file rather than creating a stub. |
Beta Was this translation helpful? Give feedback.
-
I found something in Pyright's As can be seen, the return comment ends with an ellipsis, thus not exactly matching the return type of the original code and this breaks my libcst parser, when I have this return comment as an actual return type annotation. Why? Well, the code that libcst now tries to parse is: from typing import Literal
import braintree
from braintree.resource import Resource
class UnknownPaymentMethod(Resource):
def image_url(self) -> Literal['https://assets.braintreegateway.com/payment_method…']:
return "https://assets.braintreegateway.com/payment_method_logo/unknown.png" and this |
Beta Was this translation helpful? Give feedback.
-
I've found another curious aspect of On the Pillow ImageColor.py file, the return type comment is the following: I'm not exactly sure what |
Beta Was this translation helpful? Give feedback.
-
I ran One of the functions there is the following: @pytest.mark.parametrize("expected, input",
(pytest.param(expected, input, id=id)
for id, expected, input in param_sanitizer()))
def test_sanitizer(expected, input):
parsed = parseFragment(expected)
expected = serialize(parsed,
omit_optional_tags=False,
use_trailing_solidus=True,
space_before_trailing_solidus=False,
quote_attr_values="always",
quote_char='"',
alphabetical_attributes=True)
assert expected == sanitize_html(input) And the stub file now has: @pytest.mark.parametrize("expected, input", (pytest.param(expected, input, id=id) for (id, expected, input) in param_sanitizer()}))
def test_sanitizer(expected, input): # -> None:
... However, now suddenly an excessive |
Beta Was this translation helpful? Give feedback.
-
I ran This created a nice stub file, but there was an error when parsing it with
However, when parsing this with I understand that Pyright now adds |
Beta Was this translation helpful? Give feedback.
-
I have the following piece of code, for which Pylance suggests the following return type:
![image](https://private-user-images.githubusercontent.com/24373899/281703956-21883c6f-1bee-4ab0-8c18-9e4aed62a92d.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk2NTg2NjEsIm5iZiI6MTczOTY1ODM2MSwicGF0aCI6Ii8yNDM3Mzg5OS8yODE3MDM5NTYtMjE4ODNjNmYtMWJlZS00YWIwLThjMTgtOWU0YWVkNjJhOTJkLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTUlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjE1VDIyMjYwMVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWUxMGZhMDZlM2U5M2JkYzUxYjhlN2EyOTVmYzliYmQxNDVjZTAzNmE1NjM2MGFiYmQxYTlhZWFmNDJhNjFmYzcmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.KD3BlMGICVEkTPBJ8jlCF3H4L5a1Tkcpbv0wOuJLWco)
Any | float
. This seems accurate to me.Now when I run the command
pyright --createstub
on the directory that contains this piece of code, the following stub file is created:Here for the
get_account_balance
function, the return type is to be determined to befloat
instead ofAny | float
Is this a bug? Or is this the expected functionality? Although that would seem a bit strange to me considering Pylance uses Pyright
Beta Was this translation helpful? Give feedback.
All reactions