fpgmaas/deptry

Help wanted with using tzdata on Windows (needs install but not import)

adamtheturtle opened this issue · 1 comments

Thank you for this package.

I have code equivalent to:

from zoneinfo import ZoneInfo

gmt = ZoneInfo("GMT")

on Windows, by default, this raises the following exception:

>           raise ZoneInfoNotFoundError(f"No time zone found with key {key}")
E           zoneinfo._common.ZoneInfoNotFoundError: 'No time zone found with key GMT'

This is explained by the Python documentation:

The zoneinfo module does not directly provide time zone data, and instead pulls time zone information from the system time zone database or the first-party PyPI package tzdata, if available. Some systems, including notably Windows systems, do not have an IANA database available, and so for projects targeting cross-platform compatibility that require time zone data, it is recommended to declare a dependency on tzdata. If neither system data nor tzdata are available, all calls to ZoneInfo will raise ZoneInfoNotFoundError.

I therefore have the requirement:

'tzdata; sys_platform == "win32"',

but I never import tzdata.

deptry tells me:

Assuming the corresponding module name of package 'tzdata' is 'tzdata'. Install the package or configure a package_module_name_map entry to override this behaviour.

pyproject.toml: DEP002 'tzdata' defined as a dependency but not used in the codebase

If I install the package, I still get the DEP002 error.

Is there a way that I can avoid this particular error, without ignoring valid DEP002 errors?