python / cpython

The Python programming language
https://www.python.org
Other
63.22k stars 30.28k forks source link

[doc] Document that __getattr__ can be called before __init__ (e.g. by pickle) #60446

Open ff8a353d-a1f2-4aa3-843d-9d384d733558 opened 12 years ago

ff8a353d-a1f2-4aa3-843d-9d384d733558 commented 12 years ago
BPO 16242
Nosy @pitrou, @avassalotti

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: ```python assignee = None closed_at = None created_at = labels = ['3.11', 'type-feature', 'library', 'docs'] title = '[doc] Document that __getattr__ can be called before __init__ (e.g. by pickle)' updated_at = user = 'https://bugs.python.org/powderflask' ``` bugs.python.org fields: ```python activity = actor = 'iritkatriel' assignee = 'docs@python' closed = False closed_date = None closer = None components = ['Documentation', 'Library (Lib)'] creation = creator = 'powderflask' dependencies = [] files = [] hgrepos = [] issue_num = 16242 keywords = [] message_count = 2.0 messages = ['172993', '223114'] nosy_count = 4.0 nosy_names = ['pitrou', 'alexandre.vassalotti', 'docs@python', 'powderflask'] pr_nums = [] priority = 'normal' resolution = None stage = None status = 'open' superseder = None type = 'enhancement' url = 'https://bugs.python.org/issue16242' versions = ['Python 3.11'] ```

ff8a353d-a1f2-4aa3-843d-9d384d733558 commented 12 years ago

This report is to re-raise an old issue from 2009: http://bugs.python.org/issue5370 Although that issue is marked as "fixed", I disagree that it was ever "fixed", and spent an evil day tracking it down.

Use Case:

The "resolution" for bpo-5370 was to add some documentation to Pickle. But I would argue this is insufficient - the implementer of django-crispy-forms would have no reason to ever look at the Pickle docs, and so is very likely to implement this bug (which s/he did).

Perhaps, if this issue cannot be resolved in code, as suggested by gagenellina back in 2009, at least some documentation could be added to __getattr (and others) warning that these methods could potentially be called before __init (similar to the documentation added to Pickle)? I'd be happy to draft a small bit of documentation for this, although if someone can think of a way to simply resolve this in Pickle so it does not cause the issue in the first place, that seems to me ideal.

A test case is included with bpo-5370

83d2e70e-e599-4a04-b820-3814bbdb9bef commented 10 years ago

@Joseph please accept our apologies for the delay in getting back to you.