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

RemovedInDjango40Warning: force_text() is deprecated in favor of force_str() #806

Closed
loozhengyuan opened this issue Dec 21, 2019 · 2 comments

Comments

@loozhengyuan
Copy link

loozhengyuan commented Dec 21, 2019

After recently upgrading to Django 3.0, I started to receive deprecation warnings for force_text(). As noted in the release notes:

django.utils.encoding.force_text() and smart_text()
The smart_text() and force_text() aliases (since Django 2.0) of smart_str() and force_str() are deprecated. Ignore this deprecation if your code supports Python 2 as the behavior of smart_str() and force_str() is different there.

I noted that django-storages still supports Python 2.7, but I'm not sure if support for it is going to be dropped soon or otherwise. If we're interested to address this, i'll be more than happy to follow up with a PR.

EDIT: Python 2.7 will be unsupported after January 1, 2020.

@jdufresne
Copy link
Contributor

PR #709 addresses this issue.

@jdufresne
Copy link
Contributor

jdufresne commented Jan 29, 2020

Hi @jschneier

Would you consider looking at the fix put in place for this? When I run my project's test suite, I receive hundreds of warnings from django-storages that look like the OP. The output is too noisy to be useful and could easily hide other legitimate warnings I need to fix in my own projects.

Python 2 is now officially EOL, so there is less need to continue supporting it.

Using pypinfo, here are the pip statistics for this project from the last month. You can see that Python 2 downloads make up less than 18% and has been dropping.

python_version percent download_count
3.6 38.29% 298,681
3.7 29.31% 228,595
2.7 17.68% 137,931
3.5 8.56% 66,774
3.8 5.47% 42,659
3.4 0.67% 5,212
3.9 0.01% 109
2.6 0.00% 6
3.2 0.00% 2
Total 779,969

EDIT: Users that wish to stay on Python 2.7 can continue to use the latest version of django-storages that supports Python 2. So they won't be left high and dry.

mlazowik pushed a commit to qedsoftware/django-storages that referenced this issue Mar 9, 2022
* Drop support for Python 2

Python 2 support is nearing end of life. At the end of this year, it
will no longer be supported, including for security issues.

Django has already dropped support for Python 2 in Django 2.0. Follow
upstream to be more compatible with the master branch as tests now pass.

For more details, see https://pythonclock.org/

All code changes and clean ups that were noticed were done. Changes
include:

- Remove str/unicode compatibility shims.
- Remove encoding cookies from source files. Python 3 interprets all
  files as utf-8 by default.
- Remove unnecessary __future__ imports. The features are now built-in.
- Use modern and simpler super() syntax.
- Update the wheel configuration to reflect it is no longer universal.
- Update trove classifiers.
- And more …

Also remove supported for end of life Python 3.4. It went end of life
2019-03-18.

Fixes jschneier#849

* Update uses of force_text → force_str to avoid deprecation warnings

Django deprecated force_text() and smart_text() in favor of force_str()
and smart_str() in:

django/django@d55e882

Fixes jschneier#806

* Remove unnecessary uses of (force|smart)_str

As django-storages is now Python 3 only, handling both bytes & string
paths is now unnecessary. In Python 3 with Django, paths are always
a string.

* Replace deprecated IOError with more specific FileNotFoundError

Since Python 3.3, IOError has been merged into OSError.
FileNotFoundError is a subclass, so its use is fully backwards
compatible.

* Remove unnecessary 'utf-8' from .encode()/.decode()

In Python3, these methods default to UTF-8.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants