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

fix Telnet#expect (stdlib/telnetlib.pyi) #13377

Merged
merged 1 commit into from
Jan 10, 2025

Conversation

pinterior
Copy link
Contributor

telnetlib.Telnet#expect copies given sequence and may modify it. https://github.com/python/cpython/blob/2dc476bcb9142cd25d7e1d52392b73a3dcdf1756/Lib/telnetlib.py#L612-L617
So, when a read-only sequence contains bytes (e.g. tuple of bytes) is passed to expect, TypeError is raised at runtime.

This PR fixes the argument type of the list parameter of Telnet#expect to reject Sequence containing bytes.

I know telnetlib is already removed from stdlib in Python 3.13, but this fix may help users of 3.12 and future users of https://pypi.org/project/standard-telnetlib/ etc.

Copy link
Contributor

github-actions bot commented Jan 8, 2025

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@JelleZijlstra
Copy link
Member

JelleZijlstra commented Jan 10, 2025

Looks like it only modifies the sequence after copying it (with list[:]), so I don't think we need this change.

Edit: But of course, it does fail later if the slice returns an object of an immutable type. The Sequence API doesn't require slicing to return the same type, though in practice that's what happens. So this change is slightly too restrictive in theory, but seems fine in practice.

@JelleZijlstra JelleZijlstra merged commit 46cbe78 into python:main Jan 10, 2025
64 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants