Why inspect.isclass says iter() a class?

2019-04-10 Thread Arup Rakshit
>From docs https://docs.python.org/3/library/itertools.html#itertools.chain I 
>see that itertools.chain is defined as a function. But then why 
>inspect.isclass(chain) is saying it as class.

from itertools import chain

inspect.isclass(chain)
# True


Thanks,

Arup Rakshit
[email protected]



-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Why inspect.isclass says iter() a class?

2019-04-10 Thread Calvin Spealman
Because it is. Many things are classes. calling itertools.chain(a, b)
creates an itertools.chain instance that you can iterate over. What else
did you think it would be?

On Wed, Apr 10, 2019 at 3:17 PM Arup Rakshit  wrote:

> From docs https://docs.python.org/3/library/itertools.html#itertools.chain
> I see that itertools.chain is defined as a function. But then why
> inspect.isclass(chain) is saying it as class.
>
> from itertools import chain
>
> inspect.isclass(chain)
> # True
>
>
> Thanks,
>
> Arup Rakshit
> [email protected]
>
>
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>


-- 

CALVIN SPEALMAN

SENIOR QUALITY ENGINEER

[email protected]  M: +1.336.210.5107

TRIED. TESTED. TRUSTED. 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Why inspect.isclass says iter() a class?

2019-04-10 Thread Arup Rakshit


Well. I thought so far, all class in python is defined as CamelCase. A function 
can be a class to is something I am surprised. So does this mean, any callable 
function if produce an instance is called class in Python?


Thanks,

Arup Rakshit
[email protected]



> On 11-Apr-2019, at 12:53 AM, Calvin Spealman  wrote:
> 
> Because it is. Many things are classes. calling itertools.chain(a, b) creates 
> an itertools.chain instance that you can iterate over. What else did you 
> think it would be?
> 
> On Wed, Apr 10, 2019 at 3:17 PM Arup Rakshit  wrote:
> From docs https://docs.python.org/3/library/itertools.html#itertools.chain I 
> see that itertools.chain is defined as a function. But then why 
> inspect.isclass(chain) is saying it as class.
> 
> from itertools import chain
> 
> inspect.isclass(chain)
> # True
> 
> 
> Thanks,
> 
> Arup Rakshit
> [email protected]
> 
> 
> 
> -- 
> https://mail.python.org/mailman/listinfo/python-list
> 
> 
> -- 
> CALVIN SPEALMAN
> SENIOR QUALITY ENGINEER
> [email protected]  M: +1.336.210.5107
> 
> 
> TRIED. TESTED. TRUSTED.

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Why inspect.isclass says iter() a class?

2019-04-10 Thread dieter
Arup Rakshit  writes:
> From docs https://docs.python.org/3/library/itertools.html#itertools.chain I 
> see that itertools.chain is defined as a function.

Maybe, it would have been better to state that "chain"
is a "callable": something which can be called on arguments.

For many people, "callable" is a synomym for "function",
even though Python knows other "callable"s (e.g. "class"es).

Beginners likely already know about "function" but its
generalization "callable" might be new and confuse more
than it helps. When writing documentation, you always must
balance simplicity and precision - and not everyone will
be satisfied with the resulting compromises.

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Why inspect.isclass says iter() a class?

2019-04-10 Thread Chris Angelico
On Thu, Apr 11, 2019 at 3:02 PM dieter  wrote:
>
> Arup Rakshit  writes:
> > From docs https://docs.python.org/3/library/itertools.html#itertools.chain 
> > I see that itertools.chain is defined as a function.
>
> Maybe, it would have been better to state that "chain"
> is a "callable": something which can be called on arguments.

At the moment, it isn't defined particularly as either a function or a
class, so all you can assume is that it is indeed a callable.

The docs say that it is *roughly* equivalent to the code below it. As
with most of itertools, there are a variety of edge cases that will
behave oddly in the simple sample code given, but are correctly
handled by the actual implementation.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Why inspect.isclass says iter() a class?

2019-04-10 Thread Gregory Ewing

Chris Angelico wrote:

At the moment, it isn't defined particularly as either a function or a
class,


Well, it's listed under a section called "Functions", so the reader
could be forgiven for assuming that it's a function. From a high
level point of view, it is -- you call it and it returns something.
Concretely, it happens to be implemented as a class, but that's not
something you need to know in order to use it, so the docs don't
mention it.

--
Greg
--
https://mail.python.org/mailman/listinfo/python-list


Re: Why inspect.isclass says iter() a class?

2019-04-10 Thread Chris Angelico
On Thu, Apr 11, 2019 at 3:31 PM Gregory Ewing
 wrote:
>
> Chris Angelico wrote:
> > At the moment, it isn't defined particularly as either a function or a
> > class,
>
> Well, it's listed under a section called "Functions", so the reader
> could be forgiven for assuming that it's a function.

Ah, fair point. Though the fact that the very next entry in the docs
is the "alternative constructor" chain.from_iterable, you can likely
deduce that it's actually a class.

> From a high
> level point of view, it is -- you call it and it returns something.
> Concretely, it happens to be implemented as a class, but that's not
> something you need to know in order to use it, so the docs don't
> mention it.

Exactly. Doesn't make a lot of difference whether it's a factory
function or a class.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list