Skip to content

Deprecate old backward compatible shims in configure_formatter()/handler(). #115032

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

Open
felixxm opened this issue Feb 5, 2024 · 5 comments
Open
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@felixxm
Copy link
Contributor

felixxm commented Feb 5, 2024

Feature or enhancement

Proposal:

DictConfigurator.configure_formatter() and configure_handler() contain workarounds for old configurations

#Name of parameter changed from fmt to format.
#Retry with old name.
#This is so that code can be used with older Python versions
#(e.g. by Django)
config['fmt'] = config.pop('format')
config['()'] = factory
result = self.configure_custom(config)

if "'stream'" not in str(te):
raise
#The argument name changed from strm to stream
#Retry with old name.
#This is so that code can be used with older Python versions
#(e.g. by Django)
kwargs['strm'] = kwargs.pop('stream')
result = factory(**kwargs)

Django doesn't use fmt and strm for many years. I think both can be deprecated and removed.

I'd like to prepare a patch, if accepted.

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Linked PRs

@felixxm felixxm added the type-feature A feature request or enhancement label Feb 5, 2024
@sobolevn
Copy link
Member

sobolevn commented Feb 7, 2024

cc @vsajip

@hugovk hugovk added the stdlib Python modules in the Lib dir label Feb 7, 2024
@vsajip
Copy link
Member

vsajip commented Feb 7, 2024

I realise Django doesn't use them any more, but what about other code / users? I wouldn't strongly object to removing them, but there's a chance that any such change might need to be reverted if there are complaints that it breaks existing code somewhere. And, of course, no backporting of any such change. Perhaps deprecate, but not remove immediately - rather, in line with the usual deprecation cycle. It's just a little wart in the current code, after all.

@felixxm
Copy link
Contributor Author

felixxm commented Feb 7, 2024

Perhaps deprecate, but not remove immediately - rather, in line with the usual deprecation cycle.

Yes that's what I was trying to propose. We have an existing and straightforward upgrade path i.e. use format instead of fmt and use stream instead of strm, so it seems fine to deprecate the current workarounds and remove them in 3.15 (I guess 🤔).

It's just a little wart in the current code, after all.

True, but they become an issue when there are dozens of such workarounds ("death by a thousand cuts").

@vsajip
Copy link
Member

vsajip commented Feb 7, 2024

become an issue when there are dozens of such workarounds

Well, it's not that bad IMO, but I'll look at a PR that does deprecation.

@felixxm
Copy link
Contributor Author

felixxm commented Feb 11, 2024

While preparing a patch, I noticed that we can deprecate strm, however, fmt is still needed because config is passed directly to the custom formatters and Formatter except fmt instead of format.

felixxm added a commit to felixxm/cpython that referenced this issue Feb 11, 2024
felixxm added a commit to felixxm/cpython that referenced this issue Feb 11, 2024
felixxm added a commit to felixxm/cpython that referenced this issue Feb 12, 2024
fsc-eriker pushed a commit to fsc-eriker/cpython that referenced this issue Feb 14, 2024
felixxm added a commit to felixxm/cpython that referenced this issue Apr 26, 2025
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-feature A feature request or enhancement
Projects
Status: No status
Development

No branches or pull requests

4 participants