python / cpython

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

doc: "module" of a warning might be its filename #81815

Open 1f7c169c-a6ad-45ae-b614-0d40d962c776 opened 5 years ago

1f7c169c-a6ad-45ae-b614-0d40d962c776 commented 5 years ago
BPO 37634
Nosy @blueyed

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 = ['type-bug', 'library', '3.9'] title = 'doc: "module" of a warning might be its filename' updated_at = user = 'https://github.com/blueyed' ``` bugs.python.org fields: ```python activity = actor = 'blueyed' assignee = 'none' closed = False closed_date = None closer = None components = ['Library (Lib)'] creation = creator = 'blueyed' dependencies = [] files = [] hgrepos = [] issue_num = 37634 keywords = [] message_count = 1.0 messages = ['348201'] nosy_count = 1.0 nosy_names = ['blueyed'] pr_nums = [] priority = 'normal' resolution = None stage = None status = 'open' superseder = None type = 'behavior' url = 'https://bugs.python.org/issue37634' versions = ['Python 3.9'] ```

1f7c169c-a6ad-45ae-b614-0d40d962c776 commented 5 years ago

With e.g. DeprecationWarnings for "invalid escape sequence" the "module" part is the file name (with ".py" removed), because it calls PyErr_WarnExplicitObject directly: https://github.com/python/cpython/blob/3cba3d3c55f230a59174a0dfcafb1d4685269e60/Python/ast.c#L4668-L4692

While this properly cannot be fixed to have the module name (yet), it should at least be documented then.

With warnings.warn the module is set via setup_context (https://github.com/python/cpython/blob/3cba3d3c55f230a59174a0dfcafb1d4685269e60/Python/_warnings.c#L932-L933).

This conflicts with https://github.com/python/cpython/pull/9358 (bpo-34624), which enables the documented behavior to not escape the pattern there.