Skip to content

Change locale.getdefaultlocale to getlocale #73

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
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

bahuber
Copy link

@bahuber bahuber commented Nov 22, 2023

Fix Deprecation warning in Python 3.11:

pytest_nunit\nunit.py:119: DeprecationWarning: Use setlocale(), getencoding() and getlocale() instead

Differences:

##Current##
locale.getdefaultlocale()[0]
#'en_US'

##After Deprecation##
locale.getlocale(locale.LC_CTYPE)[0]
#'English_United States'

locale.getlocale()[0].replace(' ', '-').lower()
#'english_united-states'

a = locale.getlocale()[0].replace(' ', '-').lower()
locale.locale_alias.get(a)
#'en_US.ISO8859-1'

locale.locale_alias.get(a).split('.')[0]
#'en_US'

@carlos-villavicencio-adsk

This is great to reduce several deprecation warnings on CI. Is there any plan to release this?

@Wesztman
Copy link

Wesztman commented Feb 9, 2024

Please get this merged, it has been here for several months and causes a huge spam in our CI 😢

EDIT: @tonybaloney , any plans to merge this and #72 and create a new release anytime soon? :)

@rliessum
Copy link

rliessum commented Feb 12, 2024

I was also looking into the abondance of depreciation errors and also made a pull but didn't submit it yet, since this one is here allready.

I solved (patched, in my case for Python 3.11.8 & 3.12.2) in pytest_nunit/nunit.py but just modifying according to the set best practise.

def _getlocale():
    locale.setlocale(locale.LC_ALL, '')
    current_locale=locale.getlocale()
    language_code=sys.getdefaultencoding()
    if language_code:
        return language_code
    return "en-US"

@tonybaloney
Copy link
Collaborator

This makes sense, I just wish there wasn't all the extra complexity splitting and manipulating strings along with a try..except..pass

My locale is simpler, so I wonder how many other edge cases we have to consider

>>> import locale
>>> locale.getdefaultlocale()
<stdin>:1: DeprecationWarning: Use setlocale(), getencoding() and getlocale() instead
('en_AU', 'UTF-8')
>>> locale.getlocale()
('en_AU', 'UTF-8')

@tonybaloney
Copy link
Collaborator

Further reports suggests this new locale feature can return more edge cases python/cpython#82986

I'm more tempted to mute warnings for this single call since its deprecation is scheduled for Python 3.15 and by that time hopefully the behaviour will be fixed.

@Wesztman
Copy link

Further reports suggests this new locale feature can return more edge cases python/cpython#82986

I'm more tempted to mute warnings for this single call since its deprecation is scheduled for Python 3.15 and by that time hopefully the behaviour will be fixed.

Sounds reasonable 😊👍

@rliessum
Copy link

Locale en edge cases are going hand in hand, so mute and sort out go the best approach makes sense.

@carlos-villavicencio-adsk

Would you mind recommending a way to mute warnings in the context of Azure Pipelines? pytest-nunit is a dependency of pytest-azurepipelines which we currently use.

@Wesztman
Copy link

@carlos-villavicencio-adsk if you update your lock files to use the pytest-nunit released yesterday (https://github.com/pytest-dev/pytest-nunit/releases/tag/1.0.6) you should no longer have any warnings 😊 pytest-azurepipelines should automatically use the new release.

image

@carlos-villavicencio-adsk

That's awesome @Wesztman. Thank you for the good news.

@rliessum
Copy link

Can confirm! Aweome!

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

Successfully merging this pull request may close these issues.

5 participants