From 68784f63c0219aeb2c2d816347c41222fa48cdd4 Mon Sep 17 00:00:00 2001 From: Pax <13646646+paxcodes@users.noreply.github.com> Date: Sun, 9 May 2021 05:44:55 -0700 Subject: [PATCH] fix: provide __version__ attribute (#2573) * fix: provide __version__ attribute Pyinstaller is giving an error packaging a script that uses pydantic, "AttributeError: Module 'pydantic' has no attribute '__version__'" See Issue #2572 * chore: add md file in changes folder * test: __version__ attribute of pydantic module --- changes/2572-paxcodes.md | 1 + pydantic/__init__.py | 2 ++ tests/test_version.py | 9 +++++++++ 3 files changed, 12 insertions(+) create mode 100644 changes/2572-paxcodes.md create mode 100644 tests/test_version.py diff --git a/changes/2572-paxcodes.md b/changes/2572-paxcodes.md new file mode 100644 index 0000000..aacad15 --- /dev/null +++ b/changes/2572-paxcodes.md @@ -0,0 +1 @@ +Add `__version__` attribute to pydantic module. diff --git a/pydantic/__init__.py b/pydantic/__init__.py index 2e7aab4..19e5432 100644 --- a/pydantic/__init__.py +++ b/pydantic/__init__.py @@ -14,6 +14,8 @@ from .tools import * from .types import * from .version import VERSION +__version__ = VERSION + # WARNING __all__ from .errors is not included here, it will be removed as an export here in v2 # please use "from pydantic.errors import ..." instead __all__ = [ diff --git a/tests/test_version.py b/tests/test_version.py new file mode 100644 index 0000000..ef7c928 --- /dev/null +++ b/tests/test_version.py @@ -0,0 +1,9 @@ +import pydantic + + +def test_version_attribute_is_present(): + assert hasattr(pydantic, '__version__') + + +def test_version_attribute_is_a_string(): + assert isinstance(pydantic.__version__, str)