This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Python3.5.1: type().startswith()
Type: behavior Stage: resolved
Components: Windows Versions: Python 3.5
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: SilentGhost, VertigoRay, paul.moore, steve.dower, steven.daprano, tim.golden, zach.ware
Priority: normal Keywords:

Created on 2016-05-14 06:55 by VertigoRay, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (3)
msg265505 - (view) Author: Ray (VertigoRay) Date: 2016-05-14 06:55
This doesn't look like proper functionality

    Python 3.5.1 (v3.5.1:37a07cee5969, Dec  6 2015, 01:54:25) [MSC v.1900 64 bit (AMD64)] on win32
    Type "help", "copyright", "credits" or "license" for more information.
    >>> type('')
    <class 'str'>
    >>> type('').startswith('s')
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: startswith() takes at least 1 argument (0 given)
    >>> type('').startswith('s', 's')
    True
msg265506 - (view) Author: SilentGhost (SilentGhost) * (Python triager) Date: 2016-05-14 07:08
This is exactly how methods on Python object have been behaving for year: any method can be called either as method on instance, or as method on class, with instance passed as the first argument.
msg265508 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2016-05-14 07:44
To explain in more detail: ``type('s').startswith`` is the same as ``str.startswith``, which is an unbound method in Python 2 and a regular function in Python 3. Either way, it expects *two* arguments: a string which becomes "self", and a second string argument, which is the prefix being tested for.

So type('any string').startswith('alphabet', 'al') is a long way of writing 'alphabet'.startswith('al').
History
Date User Action Args
2022-04-11 14:58:31adminsetgithub: 71204
2016-05-14 07:44:39steven.dapranosetnosy: + steven.daprano
messages: + msg265508
2016-05-14 07:08:56SilentGhostsetstatus: open -> closed
2016-05-14 07:08:20SilentGhostsetnosy: + SilentGhost
messages: + msg265506

resolution: not a bug
stage: resolved
2016-05-14 06:55:40VertigoRaycreate