You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sometimes I want to use "display.update" to update my screen. I would use dict.values() or chain() to improve performance , but it only receives an object which has "len" and "getitem". Through the test, I know some behavior the function will do.
For example, I use this py-code.
from typing import Generator, Generic, Iterable, Iterator, Protocol, Sequence, SupportsIndex,TypeVar, ValuesView
_T = TypeVar("_T",covariant=True)
class CanBeChained(Protocol[_T]):
def __iter__(self)->Iterator[_T]:...
def __len__(self) -> int: ...
class H_Chain(Generic[_T]):
content:Sequence[CanBeChained[_T]]
where:int=-1
_len:int
_generator:Generator[_T,None,None]
def __init__(self,*canBeChained:CanBeChained[_T]) -> None:
self.content=canBeChained
self._len=sum(len(i) for i in canBeChained)
self._generator=(elem for iterable in canBeChained for elem in iterable)
def __getitem__(self,__i:SupportsIndex):
print("GetItem",__i)
return next(self._generator)
def __len__(self):
return self._len
def __getattribute__(self, name: str):
print("getattribute",name)
return super().__getattribute__(name)
def test():
display.update
init();size=(300,300)
sur=display.set_mode(size,RESIZABLE)
l=H_Chain([None])#Pay attention here
display.update(l)
if __name__=="__main__":
test()
I can't understand why you can't make it generator compatible and why the "class" and "len" attributes were gotten twice, while there is one "getitem" between two "len" sometimes, which causes an error.
So, how to deal with this situation? I have only one botched solution.
class H_Chain(Generic[_T]):
content:Sequence[CanBeChained[_T]]
where:int=-1
_len:int
_generator:Generator[_T,None,None]
def __init__(self,*canBeChained:CanBeChained[_T]) -> None:
self.content=canBeChained
self._len=sum(len(i) for i in canBeChained)
def __getitem__(self,__i:SupportsIndex):
if __i==0:self._generator=(elem for iterable in self.content for elem in iterable)
return next(self._generator)
def __len__(self):return self._len
That's not a method I'm happy with.(This is my first time filing an issue, and there will be many mistakes. Please forgive me.)
Looking forward to your early reply!
The text was updated successfully, but these errors were encountered:
Indeed, display.update doesn't support generators/iterables, and the type-hinting/docs also reflects the same. I believe this shouldn't be too hard to update to support generators/iterables
I couldn't reproduce the segmentation fault with your reproducer (I had to make some fixes to get it to run, it is currently missing the pygame import).
Sometimes I want to use "display.update" to update my screen. I would use dict.values() or chain() to improve performance , but it only receives an object which has "len" and "getitem". Through the test, I know some behavior the function will do.
For example, I use this py-code.
It will print something like this:
I can't understand why you can't make it generator compatible and why the "class" and "len" attributes were gotten twice, while there is one "getitem" between two "len" sometimes, which causes an error.
So, how to deal with this situation? I have only one botched solution.
That's not a method I'm happy with.(This is my first time filing an issue, and there will be many mistakes. Please forgive me.)
Looking forward to your early reply!
The text was updated successfully, but these errors were encountered: