Skip to content

enhance: fix bytearray might be passed into lru_cached function#58

Open
JamzumSum wants to merge 2 commits intosethmlarson:masterfrom
JamzumSum:master
Open

enhance: fix bytearray might be passed into lru_cached function#58
JamzumSum wants to merge 2 commits intosethmlarson:masterfrom
JamzumSum:master

Conversation

@JamzumSum
Copy link
Copy Markdown

Most type checkers will fit bytearray into bytes automatically. However, the former is hashable but the later is not hashable. Our decode_address is a lru_cache function and requires hashable inputs. This will trigger an exception says "unhashable type: 'bytearray'".

Example:

from socksio.socks5 import SOCKS5Reply

data = bytearray(b'\x05\x00\x00\x01\x7f\x00\x00\x01\x1e\xd2')
SOCKS5Reply.loads(bytes(data))  # OK
SOCKS5Reply.loads(data)         # ValueError

Copy link
Copy Markdown
Owner

@sethmlarson sethmlarson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this, could we add a test case to ensure we don't regress on this behavior?

@JamzumSum
Copy link
Copy Markdown
Author

Thanks for this, could we add a test case to ensure we don't regress on this behavior?

Sorry for my late reply. I've add a few code to test bytearray input in 9f992b3.

@JamzumSum JamzumSum requested a review from sethmlarson January 24, 2023 02:24
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.

3 participants