-
Notifications
You must be signed in to change notification settings - Fork 657
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
some worlds: some typing in LocalRom
#3090
Conversation
### `read_bytes` It's not safe to return `bytearray` when we think it's `bytes` ```python a = rom.read_bytes(8, 3) hash(a) # This won't crash, right? ``` ### `write_bytes` `Iterable[SupportsIndex]` is what's required for `bytearray.__setitem__(slice, values)` We need to add `__len__` for the `len(values)` in this function.
world owners: |
Seems fine. |
I approve |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I approve of this change
If you are worried about people copying this. Should we maybe remove the inheritance of Otherwise this looks good to me and should be safe since it only touches typing. I've never seen |
removed the In practice, we'll probably never see any difference between |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While poorly named, if this is what our buffer calls it, we should use it and the world devs did not complain, so we good.
* some worlds: some typing in `LocalRom` ### `read_bytes` It's not safe to return `bytearray` when we think it's `bytes` ```python a = rom.read_bytes(8, 3) hash(a) # This won't crash, right? ``` ### `write_bytes` `Iterable[SupportsIndex]` is what's required for `bytearray.__setitem__(slice, values)` We need to add `__len__` for the `len(values)` in this function. * remove `object` inheritance
* some worlds: some typing in `LocalRom` ### `read_bytes` It's not safe to return `bytearray` when we think it's `bytes` ```python a = rom.read_bytes(8, 3) hash(a) # This won't crash, right? ``` ### `write_bytes` `Iterable[SupportsIndex]` is what's required for `bytearray.__setitem__(slice, values)` We need to add `__len__` for the `len(values)` in this function. * remove `object` inheritance
What is this fixing or adding?
A few people have copied this code.
Maybe we can improve it before more people copy it.
I thought about putting it in
Utils.py
, but it has some SNES specific stuff, and other variations.Also, I'm not sure how this landscape will change as people move towards not requiring roms for generation.
read_bytes
It's not safe to return
bytearray
when we think it'sbytes
I considered converting to
bytes
beforereturn
, but I think that would be a slow-down for no benefit.It's already a slice, so there's no danger of mutating the source.
And some are likely to want
bytearray
, so they would make 2 conversions just to get back to where it started.write_bytes
Some have found that they can pass a
list[int]
, and it works.Iterable[SupportsIndex]
is what's required forbytearray.__setitem__(slice, values)
We need to add
__len__
for thelen(values)
in this function.The reason I didn't add the
write_bytes
typing to dkc3 and smw, is that they both didn't have anytyping
imports in this file, so I thought it would be a little more invasive to add them.How was this tested?
unit tests and type checking