Skip to content

zoneinfo.available_timezones() emits EncodingWarning on python 3.11+ iff tzdata is installed and -X warn_default_encoding is used #137841

@tybug

Description

@tybug

Bug report

Bug description:

On a fresh install:

 ~/Desktop λ python3.11 -X warn_default_encoding
Python 3.11.8 (main, Feb  6 2024, 21:21:21) [Clang 15.0.0 (clang-1500.1.0.2.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import zoneinfo; zoneinfo.available_timezones()
...

after python3.11 -m pip install tzdata:

 ~/Desktop λ python3.11 -X warn_default_encoding
Python 3.11.8 (main, Feb  6 2024, 21:21:21) [Clang 15.0.0 (clang-1500.1.0.2.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import zoneinfo; zoneinfo.available_timezones()
/opt/homebrew/Cellar/python@3.11/3.11.8/Frameworks/Python.framework/Versions/3.11/lib/python3.11/zoneinfo/_tzpath.py:121: EncodingWarning: 'encoding' argument not specified

I tested python 3.10 (no), 3.11 (yes), 3.12 (yes), and 3.13 (yes).

This occurs because .open("r") does not specify an encoding here:

    try:
        with resources.files("tzdata").joinpath("zones").open("r") as f:
            for zone in f:
                zone = zone.strip()
                if zone:
                    valid_zones.add(zone)
    except (ImportError, FileNotFoundError):
        pass

CPython versions tested on:

3.11

Operating systems tested on:

macOS

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibPython modules in the Lib dirtype-bugAn unexpected behavior, bug, or error

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions