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

Instance remembers old values from former life #46813

Closed
warnhold mannequin opened this issue Apr 6, 2008 · 2 comments
Closed

Instance remembers old values from former life #46813

warnhold mannequin opened this issue Apr 6, 2008 · 2 comments
Labels
type-bug An unexpected behavior, bug, or error

Comments

@warnhold
Copy link
Mannequin

warnhold mannequin commented Apr 6, 2008

BPO 2561
Nosy @birkenfeld
Files
  • class_with_listparamdefault.py
  • 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-04-06.08:30:51.074>
    created_at = <Date 2008-04-06.07:31:58.201>
    labels = ['type-bug']
    title = 'Instance remembers old values from former life'
    updated_at = <Date 2008-04-06.08:30:51.037>
    user = 'https://bugs.python.org/warnhold'

    bugs.python.org fields:

    activity = <Date 2008-04-06.08:30:51.037>
    actor = 'georg.brandl'
    assignee = 'none'
    closed = True
    closed_date = <Date 2008-04-06.08:30:51.074>
    closer = 'georg.brandl'
    components = []
    creation = <Date 2008-04-06.07:31:58.201>
    creator = 'warnhold'
    dependencies = []
    files = ['9959']
    hgrepos = []
    issue_num = 2561
    keywords = []
    message_count = 2.0
    messages = ['65024', '65025']
    nosy_count = 2.0
    nosy_names = ['georg.brandl', 'warnhold']
    pr_nums = []
    priority = 'normal'
    resolution = 'wont fix'
    stage = None
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue2561'
    versions = ['Python 2.5']

    @warnhold
    Copy link
    Mannequin Author

    warnhold mannequin commented Apr 6, 2008

    I don't know if it is a bug or a feature but the result seems to be
    wrong for me: A constructor argument remembers its values from the last call

    @warnhold warnhold mannequin added the type-bug An unexpected behavior, bug, or error label Apr 6, 2008
    @birkenfeld
    Copy link
    Member

    Yes, this is expected. Default values are only evaluated once, at
    function creation time. If you need to have a mutable default argument
    that is assigned to something and changed, use something like this:

    def f(arg=None):
        if arg is None:
            arg = []
        ...

    @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
    type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant