GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — bpo-29571: Fix test_re.test_locale_flag() by vstinner · Pull Request #12099 · python/cpython

Conversation

@vstinner

@vstinner vstinner commented Feb 28, 2019 •
edited by bedevere-bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Use locale.getpreferredencoding() rather than locale.getlocale() to
get the locale encoding. With some locales, locale.getlocale()
returns the wrong encoding.

For example, on Fedora 29, locale.getlocale() returns ISO-8859-1
encoding for the "en_IN" locale, whereas
locale.getpreferredencoding() reports the correct encoding: UTF-8.

https://bugs.python.org/issue29571

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@vstinner
bpo-29571: Fix test_re.test_locale_flag()
329e74d
Use locale.getpreferredencoding() rather than locale.getlocale() to
get the locale encoding. With some locales, locale.getlocale()
returns the wrong encoding.

For example, on Fedora 29, locale.getlocale() returns ISO-8859-1
encoding for the "en_IN" locale, whereas
locale.getpreferredencoding() reports the correct encoding: UTF-8.
@the-knights-who-say-ni the-knights-who-say-ni added the CLA signed label Feb 28, 2019
@bedevere-bot bedevere-bot added tests Tests in the Lib/test dir awaiting merge labels Feb 28, 2019
@vstinner

vstinner commented Feb 28, 2019

Copy link
Copy Markdown
Member Author

I tested manually the PR on Fedora 29.

Without the fix:

$ LANG=en_IN ./python -m test test_re
...
test test_re failed -- Traceback (most recent call last):
  File "/home/vstinner/prog/python/master/Lib/test/test_re.py", line 1576, in test_locale_flag
    self.assertTrue(pat.match(bletter))
AssertionError: None is not true
...
Tests result: FAILURE

With the fix:

$ LANG=en_IN ./python -m test test_re
...
Tests result: SUCCESS
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

4383
4383 approved these changes Feb 28, 2019
View reviewed changes
@bedevere-bot bedevere-bot added awaiting core review and removed awaiting merge labels Feb 28, 2019
@tirkarthi

tirkarthi commented Feb 28, 2019

Copy link
Copy Markdown
Member

I can confirm the issue and the PR fixes the issue. But would like to know the difference between this PR and #149 since they both seem to return the same result but #149 ended up breaking Windows and had to be reverted with #554 meanwhile current PR works with windows CI.

karthi@ubuntu-s-1vcpu-1gb-blr1-01:~/cpython$ LANG=en_IN LC_ALL=en_IN ./python -c 'import locale; print(locale.getpreferredencoding(False))'
UTF-8
karthi@ubuntu-s-1vcpu-1gb-blr1-01:~/cpython$ LANG=en_IN LC_ALL=en_IN ./python -c 'import locale; print(locale.getpreferredencoding())'
UTF-8
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner

vstinner commented Feb 28, 2019

Copy link
Copy Markdown
Member Author

But would like to know the difference between this PR and #149 since they both seem to return the same result but #149 ended up breaking Windows and had to be reverted with #554 meanwhile current PR works with windows CI.

Honestly, I don't know:
https://bugs.python.org/issue29571#msg336877

The two Windows CIs passed on this PR. I also tested manually the PR on my Windows VM and it passed.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner vstinner added the needs backport to 3.7 label Feb 28, 2019
@vstinner
vstinner merged commit ab71f8b into python:master Feb 28, 2019
@bedevere-bot bedevere-bot removed the awaiting core review label Feb 28, 2019
@miss-islington

miss-islington commented Feb 28, 2019

Copy link
Copy Markdown
Contributor

Thanks @vstinner for the PR 🌮🎉.. I'm working now to backport this PR to: 3.7.
🐍🍒⛏🤖 I'm not a witch! I'm not a witch!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner
vstinner deleted the test_locale_flag branch February 28, 2019 23:08
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Feb 28, 2019
@vstinner @miss-islington
bpo-29571: Fix test_re.test_locale_flag() (pythonGH-12099)
1a311ad
Use locale.getpreferredencoding() rather than locale.getlocale() to
get the locale encoding. With some locales, locale.getlocale()
returns the wrong encoding.

For example, on Fedora 29, locale.getlocale() returns ISO-8859-1
encoding for the "en_IN" locale, whereas
locale.getpreferredencoding() reports the correct encoding: UTF-8.
(cherry picked from commit ab71f8b)

Co-authored-by: Victor Stinner <[email protected]>
@bedevere-bot bedevere-bot removed the needs backport to 3.7 label Feb 28, 2019
@bedevere-bot

bedevere-bot commented Feb 28, 2019

Copy link
Copy Markdown

GH-12108 is a backport of this pull request to the 3.7 branch.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

1 more reviewer
@4383 4383 4383 approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

tests Tests in the Lib/test dir

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

6 participants

@vstinner @tirkarthi @miss-islington @bedevere-bot @4383 @the-knights-who-say-ni
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.