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-46659: calendar uses locale.getlocale() by vstinner · Pull Request #31166 · python/cpython

Conversation

@vstinner

@vstinner vstinner commented Feb 6, 2022 •
edited by bedevere-bot
Loading

Uh oh!

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

Copy link
Copy Markdown
Member

The calendar.LocaleTextCalendar and calendar.LocaleHTMLCalendar
classes module now use locale.getlocale(), instead of using
locale.getdefaultlocale(), if no locale is specified.

https://bugs.python.org/issue46659

Sorry, something went wrong.

Uh oh!

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

All reactions
@vstinner
bpo-46659: calendar uses locale.getlocale()
74ca535
The calendar.LocaleTextCalendar and calendar.LocaleHTMLCalendar
classes module now use locale.getlocale(), instead of using
locale.getdefaultlocale(), if no locale is specified.
@the-knights-who-say-ni the-knights-who-say-ni added the CLA signed label Feb 6, 2022
@bedevere-bot bedevere-bot added the awaiting core review label Feb 6, 2022
@vstinner

vstinner commented Feb 6, 2022

Copy link
Copy Markdown
Member Author

cc @serhiy-storchaka @malemburg @methane

All reactions

Sorry, something went wrong.

Uh oh!

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

@vstinner

vstinner commented Feb 6, 2022 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Member Author

Example with cal_locale.py attached to bpo-46659. Run the program in English, but switch to a french locale before creating the LocaleTextCalendar() instance.

Current behavior: calendar speaks English, even if the current LC_TIME locale is French:

$ LC_ALL=en_US.utf8 ./python cal_locale.py fr_FR.utf8
locale.getlocale()=('fr_FR', 'UTF-8')
locale.getdefaultlocale()=('en_US', 'UTF-8')
cal.locale=('en_US', 'UTF-8')
                                August 2022
  Monday    Tuesday   Wednesday   Thursday    Friday    Saturday    Sunday
     1          2          3          4          5          6          7
     8          9         10         11         12         13         14
    15         16         17         18         19         20         21
    22         23         24         25         26         27         28
    29         30         31

With this PR: calendar speaks French:

$ LC_ALL=en_US.utf8 ./python cal_locale.py fr_FR.utf8
locale.getlocale()=('fr_FR', 'UTF-8')
locale.getdefaultlocale()=('en_US', 'UTF-8')
cal.locale=('fr_FR', 'UTF-8')
                                 août 2022
  lundi      mardi     mercredi    jeudi     vendredi    samedi    dimanche
     1          2          3          4          5          6          7
     8          9         10         11         12         13         14
    15         16         17         18         19         20         21
    22         23         24         25         26         27         28
    29         30         31

Applications which don't call setlocale() to change the LC_ALL or LC_TIME locale are not affected.

All reactions

Sorry, something went wrong.

Uh oh!

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

methane
methane approved these changes Feb 7, 2022
View reviewed changes
@bedevere-bot bedevere-bot added awaiting merge and removed awaiting core review labels Feb 7, 2022
@serhiy-storchaka

serhiy-storchaka commented Feb 7, 2022

Copy link
Copy Markdown
Member

Would not be more correct to use locale.getlocale(locale.LC_TIME)?

All reactions

Sorry, something went wrong.

Uh oh!

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

@vstinner
Get the LC_TIME locale
8a3e901
@vstinner

vstinner commented Feb 7, 2022

Copy link
Copy Markdown
Member Author

With this PR, the two classes store the current locale when an instance is created. Is it really an important feature?

Or would it be acceptable to use the current locale (don't change the locale) if locale=None is passed (default behavior)?

All reactions

Sorry, something went wrong.

Uh oh!

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

@vstinner

vstinner commented Feb 7, 2022

Copy link
Copy Markdown
Member Author

Would not be more correct to use locale.getlocale(locale.LC_TIME)?

You're right: done.

All reactions

Sorry, something went wrong.

Uh oh!

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

@vstinner
vstinner merged commit 7a0486e into python:main Feb 7, 2022
@bedevere-bot bedevere-bot removed the awaiting merge label Feb 7, 2022
@vstinner
vstinner deleted the calendar_defaultlocale branch February 7, 2022 23:24
@vstinner

vstinner commented Feb 7, 2022

Copy link
Copy Markdown
Member Author

Merged, thanks for your reviews.

With this PR, the two classes store the current locale when an instance is created. Is it really an important feature?

In case of doubt, I prefer to leave the code as it is.

All reactions

Sorry, something went wrong.

Uh oh!

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

@vstinner vstinner mentioned this pull request Dec 11, 2022
Deprecate locale.getdefaultlocale() function #90817
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@methane methane methane approved these changes

Uh oh!

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

Assignees

No one assigned

Labels

None yet

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.

5 participants

@vstinner @serhiy-storchaka @methane @the-knights-who-say-ni @bedevere-bot
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.