-
Notifications
You must be signed in to change notification settings - Fork 706
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
BizHawkClient: Fix typing mistake #3938
Conversation
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.
LGTM and hits all the instances of this
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.
An infinite generator would be a problem with almost everything typed with Iterable
.
I think that's not really a problem with the Iterable
typing. It's a problem with making and using an infinite generator.
But this change is not bad if you want it.
The thing I would be more concerned about is typing.List
for read_list
and guard_list
and write_list
. That makes it more difficult to get valid typing at the call site.
Those could be changed to Iterable
or Sequence
to make things easier for callers.
Generally, if you're not mutating the parameter in the function, you should use an immutable interface for the parameter type annotation.
BTW, But after thinking about it more, I think So I would use async def guarded_read(ctx: BizHawkContext,
read_list: typing.Sequence[typing.Tuple[int, int, str]],
guard_list: typing.Sequence[typing.Tuple[int, typing.Sequence[int], str]]) -> typing.Optional[typing.Sequence[bytes]]: and a similar change in the other functions |
Someone's mypy complained about
I'm not sure it makes sense to change the return type though, since we're just explicitly creating and returning a list. No reason to add extra abstraction. |
What is this fixing or adding?
The type
Iterable[int]
was used in a few places to indicate some sort of list of integers. Specifically something that can be passed into thebytes
constructor. It's almost accurate, but not specific enough. A generator that never stops iterating fitsIterable[int]
, but would be wrong here.The actual type for what you can pass into
bytes
according to my IDE isIterable[SupportsIndex] | SupportsIndex | SupportsBytes | ReadableBuffer
. From what I can tell,Sequence[int]
is a subset ofIterable[SupportsIndex]
, and it's still concise and descriptive.How was this tested?
Did a few
isinstance
s in a REPL and briefly opened an Emerald patch to make sure things didn't crash.