Skip to content

strage default value behaviour #48208

Closed
Closed

Description

@dominikholler
BPO 3958
Nosy @amauryfa
Files
  • test.py
  • index.html
  • 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 = None
    closed_at = <Date 2008-09-24.15:58:27.208>
    created_at = <Date 2008-09-24.15:17:22.678>
    labels = ['invalid']
    title = 'strage default value behaviour'
    updated_at = <Date 2008-09-24.18:33:04.323>
    user = 'https://bugs.python.org/dominikholler'

    bugs.python.org fields:

    activity = <Date 2008-09-24.18:33:04.323>
    actor = 'dominik.holler'
    assignee = 'none'
    closed = True
    closed_date = <Date 2008-09-24.15:58:27.208>
    closer = 'amaury.forgeotdarc'
    components = ['None']
    creation = <Date 2008-09-24.15:17:22.678>
    creator = 'dominik.holler'
    dependencies = []
    files = ['11593', '11594']
    hgrepos = []
    issue_num = 3958
    keywords = []
    message_count = 3.0
    messages = ['73718', '73723', '73745']
    nosy_count = 2.0
    nosy_names = ['amaury.forgeotdarc', 'dominik.holler']
    pr_nums = []
    priority = 'normal'
    resolution = 'not a bug'
    stage = None
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue3958'
    versions = ['Python 2.5', 'Python 2.4']

    Activity

    1. dominikholler commented on Sep 24, 2008

      dominikhollermannequin
      MannequinAuthor

      The behaviour is changing, if I toogle comment lines 10 + 11.

      Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit
      (Intel)] on
      win32

    2. amauryfa commented on Sep 24, 2008

      @amauryfa
      Contributor

      Your script is subject to the "shared default value" syndrome, explained
      here:
      http://www.python.org/doc/faq/general/#why-are-default-values-shared-between-objects

      As indicated in the FAQ, your function could be rewritten like this:

      def getElementsByAttrib(self, value, AName="ID-REF", list=None):
        if list is None:
            list = []
        ...

      to have a less surprising behavior.

    3. dominikholler commented on Sep 24, 2008

      dominikhollermannequin
      MannequinAuthor

      thx
      sorry reporting this bug

    4. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      No labels
      No labels

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions