Skip to content

Incorrect stub file causes type checking error #125

@stinodego

Description

@stinodego

The new release of mypy 1.0.0 exposed a problem in the typing of this module.

The issue

Consider the following code:

from backports.zoneinfo import ZoneInfo

tzinfo = ZoneInfo("Pacific/Rarotonga")  # Type error

Type-checking this with mypy will result in the following error:

repro.py:3: error: Cannot instantiate abstract class "ZoneInfo" with abstract attributes "dst", "tzname" and "utcoffset"  [abstract]

The solution

After some investigation, I noticed that the type stub file of backports.zoneinfo does not contain type information for the abstract methods of ZoneInfo. The solution would be to add types for these methods.

I don't mind making a PR for this if you want to make a new release including this fix. Let me know.

The workaround

A workaround for dealing with this issue is to import ZoneInfo from the submodule directly:

from backports.zoneinfo._zoneinfo import ZoneInfo

tzinfo = ZoneInfo("Pacific/Rarotonga")  # OK

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions