Aaron Bingham schrieb: > Georg Brandl wrote: >> Greg Ewing schrieb: >> >>> Scott Dial wrote: >>> >>> A tangential question -- why are TemporaryFile and >>> NamedTemporaryFile named in TitleCase, when they're >>> functions and not classes? >>> >> >> Probably because they are factory functions potentially returning a >> _TemporaryFileWrapper. If they were "functions", they'd have to be >> verbed, e.g. "make_temporary_file()". >> >> The class/function distinction is not so clear in Python from the user's >> point of view since there is no different calling syntax. > Actually the distinction is very clear: > > >>> class _PrivateClass(object): > ... pass > ... > >>> def FunctionNamedToLookLikeClass(): > ... return _PrivateClass() > ... > >>> pc = _PrivateClass() > >>> isinstance(pc, _PrivateClass) > True > >>> fntllc = FunctionNamedToLookLikeClass() > >>> isinstance(fntllc, FunctionNamedToLookLikeClass) > Traceback (most recent call last): > File "<stdin>", line 1, in <module> > TypeError: isinstance() arg 2 must be a class, type, or tuple of classes > and types > > That's sure to be an unpleasant surprise for someone.
<whisper>duck typing...</whisper> But you have a valid point. Georg _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com