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

Multiline literal types in CRLF ending files are not normalized to LF #9681

Closed
jairinhohw opened this issue Jan 10, 2025 · 2 comments
Closed
Labels
addressed in next version Issue is fixed and will appear in next published version bug Something isn't working

Comments

@jairinhohw
Copy link

Comparing a type of a multiline literal in a file with CRLF line ending does not match the same literal in a file with LF ending.

This makes the code below type check if the file has CF line ending, but error if the file has a CRLF line ending.

from typing import Literal

a: Literal[
    "a\nb"
] = """a
b"""

print(repr(a))

running the file prints 'a\nb' in both cases, so the line ending of the python file should not matter.

VS Code extension or command-line
Tested with both the pylance extension and the pyright command line tool version 1.1.391

Error returned, with CRLF file:

/tmp/tst/tst.py
  /tmp/tst/tst.py:5:5 - error: Type "Literal['a\r\nb']" is not assignable to declared type "Literal['a\nb']"
    "Literal['a\r\nb']" is not assignable to type "Literal['a\nb']" (reportAssignmentType)
@jairinhohw jairinhohw added the bug Something isn't working label Jan 10, 2025
erictraut added a commit that referenced this issue Jan 10, 2025
…RLF to LF within multi-line triple-quoted strings so the behavior is consistent with runtime. This addresses #9681.
erictraut added a commit that referenced this issue Jan 10, 2025
…RLF to LF within multi-line triple-quoted strings so the behavior is consistent with runtime. This addresses #9681.
erictraut added a commit that referenced this issue Jan 10, 2025
…RLF to LF within multi-line triple-quoted strings so the behavior is consistent with runtime. This addresses #9681.
erictraut added a commit that referenced this issue Jan 10, 2025
…RLF to LF within multi-line triple-quoted strings so the behavior is consistent with runtime. This addresses #9681. (#9690)
@erictraut
Copy link
Collaborator

Thanks for the bug report. I couldn't find any official documentation that indicates this is the behavior of the Python runtime, but I confirmed the behavior through experimentation. I've updated pyright's logic accordingly. This will be addressed in the next release.

@erictraut erictraut added the addressed in next version Issue is fixed and will appear in next published version label Jan 10, 2025
@erictraut
Copy link
Collaborator

This is included in pyright 1.1.392.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addressed in next version Issue is fixed and will appear in next published version bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants