Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add notes to the manual about is and methods #42812

Closed
collinwinter mannequin opened this issue Jan 20, 2006 · 7 comments
Closed

Add notes to the manual about is and methods #42812

collinwinter mannequin opened this issue Jan 20, 2006 · 7 comments
Assignees
Labels
docs Documentation in the Doc dir easy type-feature A feature request or enhancement

Comments

@collinwinter
Copy link
Mannequin

collinwinter mannequin commented Jan 20, 2006

BPO 1410739
Nosy @mwhudson, @freddrake, @birkenfeld, @amauryfa, @tiran
Files
  • ref3.tex.diff: Patch to Doc/ref/ref3.tex, r42105
  • issue1410739.patch: Patch to Doc/reference/expressions.rst
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/birkenfeld'
    closed_at = <Date 2008-07-01.20:50:15.718>
    created_at = <Date 2006-01-20.12:39:49.000>
    labels = ['easy', 'type-feature', 'docs']
    title = 'Add notes to the manual about `is` and methods'
    updated_at = <Date 2008-07-01.20:50:15.717>
    user = 'https://bugs.python.org/collinwinter'

    bugs.python.org fields:

    activity = <Date 2008-07-01.20:50:15.717>
    actor = 'georg.brandl'
    assignee = 'georg.brandl'
    closed = True
    closed_date = <Date 2008-07-01.20:50:15.718>
    closer = 'georg.brandl'
    components = ['Documentation']
    creation = <Date 2006-01-20.12:39:49.000>
    creator = 'collinwinter'
    dependencies = []
    files = ['6964', '10263']
    hgrepos = []
    issue_num = 1410739
    keywords = ['patch', 'easy']
    message_count = 7.0
    messages = ['49355', '49356', '49357', '61910', '61911', '66555', '69075']
    nosy_count = 7.0
    nosy_names = ['mwh', 'fdrake', 'georg.brandl', 'collinwinter', 'amaury.forgeotdarc', 'christian.heimes', 'werneck']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = None
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue1410739'
    versions = ['Python 2.6']

    @collinwinter
    Copy link
    Mannequin Author

    collinwinter mannequin commented Jan 20, 2006

    This patch, made against svn revision 42105, adds
    caveats to Doc/ref/ref3.tex concerning the use of the
    is operator in conjunction with class- and
    instance-methods.

    As I was recently bitten by trying to do the equivalent of
    """
    >>> MyClass.a_class_method is MyClass.a_class_method
    False
    >>>
    """
    I thought the manual might benefit from coverage of
    this as-yet-undocumented area.

    @collinwinter collinwinter mannequin assigned freddrake Jan 20, 2006
    @collinwinter collinwinter mannequin added the docs Documentation in the Doc dir label Jan 20, 2006
    @collinwinter collinwinter mannequin assigned freddrake Jan 20, 2006
    @collinwinter collinwinter mannequin added the docs Documentation in the Doc dir label Jan 20, 2006
    @mwhudson
    Copy link

    Logged In: YES
    user_id=6656

    I'm not really sure this patch is a good idea. It seems over-specific to one
    particular pitfall. Maybe instead warning stickers should be attached to the
    description of the 'is' operator.

    @collinwinter
    Copy link
    Mannequin Author

    collinwinter mannequin commented Jan 21, 2006

    Logged In: YES
    user_id=1344176

    I'm not sure a full-blown caveat on is is a good idea,
    unless this particular issue impacts areas beyond
    {class,instance}methods (the only two places I've see it).
    However, tacking a note to is, something like "you may
    notice unusal behaviour in certain combinations of is and
    class- and instancemethods; see their docs for more info",
    would probably be a good idea.

    I tried to make the original doc patch as specific as
    possible because it's a tricky problem. There's a good
    explanation for the following behaviour, but until someone
    expalins it to you, you're probably going to think it's a bug.
    """
    >>> id(MyClass.class_method) == id(MyClass.class_method)
    True
    >>> MyClass.class_method is MyClass.class_method
    False
    """

    @amauryfa
    Copy link
    Member

    An even more surprising example:

    >>> id([1]) == id([2])
    True

    @tiran
    Copy link
    Member

    tiran commented Jan 31, 2008

    The example sure is surprising for somebody without intimate knowledge
    about Python's memory management. Although the is operator is
    implemented as id(a) == id(b) reference counting, free lists and arenas
    can cause some surprising effects.

    @tiran tiran added the easy label Jan 31, 2008
    @tiran tiran added type-feature A feature request or enhancement easy labels Jan 31, 2008
    @tiran tiran added the type-feature A feature request or enhancement label Jan 31, 2008
    @werneck
    Copy link
    Mannequin

    werneck mannequin commented May 10, 2008

    I agree it's not a good idea to be too much specific about this. The
    patch attached adds the following footnote to the 'is' operator:

    Due to automatic garbage-collection, free lists, and the dynamic nature
    of descriptors, you may notice unusual behaviour in certain combinations
    of :keyword:`is` operator, like those involving identity comparisons
    between class and instancemethods, and free instances in the same
    expression. Check their docs for more info.

    @birkenfeld
    Copy link
    Member

    Reworded a bit and applied as r64638.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    docs Documentation in the Doc dir easy type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    5 participants