Skip to content

Deprecate __version__ attribute #897

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

Merged
merged 1 commit into from
Apr 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions src/pendulum/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

import datetime as _datetime

from typing import Any
from typing import Union
from typing import cast
from typing import overload

from pendulum.__version__ import __version__
from pendulum.constants import DAYS_PER_WEEK
from pendulum.constants import HOURS_PER_DAY
from pendulum.constants import MINUTES_PER_HOUR
Expand Down Expand Up @@ -343,6 +343,23 @@ def interval(
travel_to = _traveller.travel_to
travel_back = _traveller.travel_back


def __getattr__(name: str) -> Any:
if name == "__version__":
import importlib.metadata
import warnings

warnings.warn(
"The '__version__' attribute is deprecated and will be removed in"
" Pendulum 3.4. Use 'importlib.metadata.version(\"pendulum\")' instead.",
DeprecationWarning,
stacklevel=2,
)
return importlib.metadata.version("pendulum")

raise AttributeError(name)


__all__ = [
"DAYS_PER_WEEK",
"HOURS_PER_DAY",
Expand All @@ -364,7 +381,6 @@ def interval(
"Time",
"Timezone",
"WeekDay",
"__version__",
"date",
"datetime",
"duration",
Expand Down
4 changes: 0 additions & 4 deletions src/pendulum/__version__.py

This file was deleted.