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

Should warnings.warn default to stacklevel=2? #88462

Open
asottile mannequin opened this issue Jun 2, 2021 · 2 comments
Open

Should warnings.warn default to stacklevel=2? #88462

asottile mannequin opened this issue Jun 2, 2021 · 2 comments
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error type-feature A feature request or enhancement

Comments

@asottile
Copy link
Mannequin

asottile mannequin commented Jun 2, 2021

BPO 44296
Nosy @asottile

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 = None
created_at = <Date 2021-06-02.23:55:20.255>
labels = ['type-bug', 'library', '3.11']
title = 'Should warnings.warn default to stacklevel=2?'
updated_at = <Date 2021-06-02.23:55:20.255>
user = 'https://github.com/asottile'

bugs.python.org fields:

activity = <Date 2021-06-02.23:55:20.255>
actor = 'Anthony Sottile'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['Library (Lib)']
creation = <Date 2021-06-02.23:55:20.255>
creator = 'Anthony Sottile'
dependencies = []
files = []
hgrepos = []
issue_num = 44296
keywords = []
message_count = 1.0
messages = ['394960']
nosy_count = 1.0
nosy_names = ['Anthony Sottile']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue44296'
versions = ['Python 3.11']

@asottile
Copy link
Mannequin Author

asottile mannequin commented Jun 2, 2021

I have yet to come across a usecase where stacklevel=1 makes sense -- usually it is more helpful to point at the calling code than the function which is itself warning

my proposal is to update the default for stacklevel= from 1 to 2

an example bpo where this is relevant is bpo-44295

@asottile asottile mannequin added 3.11 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Jun 2, 2021
@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
@gpshead
Copy link
Member

gpshead commented Jan 1, 2023

stacklevel is also often not a great API as it's an integer that depends on a pile of calling code far from the warnings.warn call itself. #39615 is likely to provide a more useful API. check the module/file of the stack frame and bubble up outside of the current file/module/package or a set of such.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

1 participant