Skip to content
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

Unsupported signature checking for overloads of str() #738

Closed
MunchDev opened this issue Jun 18, 2020 · 2 comments
Closed

Unsupported signature checking for overloads of str() #738

MunchDev opened this issue Jun 18, 2020 · 2 comments
Labels
as designed Not a bug, working as intended

Comments

@MunchDev
Copy link

Describe the bug
No overloads for "str(str(a), "utf-8")" match parameters
Argument types: (str, Literal['utf-8']) Pyright (reportGeneralTypeIssues)

To Reproduce

# Byte string
a = b'...'

# No PyRight
a = str(a, 'utf-8') # OK

# With PyRight
a = str(a, 'utf-8') # Report the error above

Expected behavior
String encoding should be allowed

Screenshots or Code
If applicable, add screenshots or the text of the code (surrounded by triple back ticks) to help explain your problem.

# Download raw data
raw_data: List[str] = list(urlopen(url))

# Remove unnecessary escape characters and
# apply Python-default encoding
pre_processed_data: List[str] = list(map(lambda a: str(str(a), "utf-8")[:-1], raw_data))

VS Code extension or command-line
PyRight as VS Code extension (v1.1.43)

Additional context
Can be turned off by removing type hinting

@erictraut
Copy link
Collaborator

Pyright is doing the correct thing here. The typeshed stdlib "builtins.pyi" file specifies that the constructor for the str class must conform to one of the following overloads:

@overload
def __init__(self, o: object = ...) -> None: ...
@overload
def __init__(self, o: bytes, encoding: str = ..., errors: str = ...) -> None: ...

In your example above, the variable a is of type str at the time you call the str constructor the second time, and according to the builtins.pyi type information, this is not allowed.

If you believe this error is incorrect, you'll need to file a bug against (or submit a PR to) the typeshed repo. Pyright relies on the typeshed stubs for type information.

@erictraut erictraut added the as designed Not a bug, working as intended label Jun 18, 2020
@MunchDev
Copy link
Author

Oh, I see the problem to my side. Thanks @erictraut for pointing out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
as designed Not a bug, working as intended
Projects
None yet
Development

No branches or pull requests

2 participants