Skip to content
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

Incorrect stub file causes type checking error #125

Open
stinodego opened this issue Feb 9, 2023 · 0 comments · May be fixed by #126
Open

Incorrect stub file causes type checking error #125

stinodego opened this issue Feb 9, 2023 · 0 comments · May be fixed by #126

Comments

@stinodego
Copy link

stinodego commented Feb 9, 2023

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
andersk added a commit to andersk/zoneinfo that referenced this issue Mar 4, 2023
andersk added a commit to andersk/zoneinfo that referenced this issue Mar 8, 2023
pganssle pushed a commit to andersk/zoneinfo that referenced this issue Mar 10, 2023
sbrudenell added a commit to sbrudenell/btrfs2s3 that referenced this issue Jun 26, 2024
among other things, I hadn't realized that types-all was deprecated.

this change exposed pganssle/zoneinfo#125. I
have no explanation for why it wasn't exposed before, but rather than
investigate this I'll choose to just fix it and assume it was previously
shadowed by something in types-all.
sbrudenell added a commit to sbrudenell/btrfs2s3 that referenced this issue Jun 26, 2024
among other things, I hadn't realized that types-all was deprecated.

this change exposed pganssle/zoneinfo#125. I
have no explanation for why it wasn't exposed before, but rather than
investigate this I'll choose to just fix it and assume it was previously
shadowed by something in types-all.
sbrudenell added a commit to sbrudenell/btrfs2s3 that referenced this issue Jun 26, 2024
among other things, I hadn't realized that types-all was deprecated.

this change exposed pganssle/zoneinfo#125. I
have no explanation for why it wasn't exposed before, but rather than
investigate this I'll choose to just fix it and assume it was previously
shadowed by something in types-all.
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 a pull request may close this issue.

1 participant