Created
July 23, 2020 12:28
-
-
Save Pentusha/a0a76ae79ea4846365d34e22ea07b716 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections.abc import Iterable, Iterator | |
from types import GeneratorType | |
class OnlyIter: | |
def __iter__(self): | |
return self | |
class OnlyNext: | |
def __init__(self): | |
self._n = 0 | |
def __next__(self): | |
if self._n < 10: | |
return 1 | |
else: | |
raise StopIteration() | |
class IterNext(OnlyIter, OnlyNext): | |
pass | |
def gen(): | |
yield 1 | |
print(f""" | |
{isinstance((_ for _ in range(10)), GeneratorType)=} | |
{isinstance(range(10), GeneratorType)=} | |
{isinstance(gen(), GeneratorType)=} | |
{isinstance(gen(), Iterable)=} | |
{isinstance(gen(), Iterator)=} | |
{isinstance(iter(gen()), Iterable)=} | |
{isinstance(iter(gen()), Iterator)=} | |
{isinstance(range(10), Iterable)=} | |
{isinstance(range(10), Iterator)=} | |
{isinstance(iter(range(10)), Iterable)=} | |
{isinstance(iter(range(10)), Iterator)=} | |
{isinstance(OnlyNext(), Iterable)=} | |
{isinstance(OnlyNext(), Iterator)=} | |
{isinstance(OnlyIter(), Iterable)=} | |
{isinstance(OnlyIter(), Iterator)=} | |
{isinstance(IterNext(), Iterable)=} | |
{isinstance(IterNext(), Iterator)=} | |
""") |
Author
Pentusha
commented
Jul 23, 2020
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment