From: Daniele Varrazzo Date: Thu, 28 Oct 2021 15:33:00 +0000 (+0200) Subject: Make __version__ importable, although not included in __all__ X-Git-Tag: 3.0.2~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4f26b47a60ec8faef4b89c66435b2ce84b9885b7;p=thirdparty%2Fpsycopg.git Make __version__ importable, although not included in __all__ --- diff --git a/psycopg/psycopg/__init__.py b/psycopg/psycopg/__init__.py index 368b8ef66..20d675e25 100644 --- a/psycopg/psycopg/__init__.py +++ b/psycopg/psycopg/__init__.py @@ -28,7 +28,7 @@ from .dbapi20 import BINARY, DATETIME, NUMBER, ROWID, STRING from .dbapi20 import Binary, Date, DateFromTicks, Time, TimeFromTicks from .dbapi20 import Timestamp, TimestampFromTicks -from .version import __version__ +from .version import __version__ as __version__ # noqa: F401 # Set the logger to a quiet default, can be enabled if needed logger = logging.getLogger("psycopg") @@ -55,7 +55,6 @@ types.array.register_all_arrays(adapters) # this is the canonical place to obtain them and should be used by MyPy too, # so that function signatures are consistent with the documentation. __all__ = [ - "__version__", "AsyncConnection", "AsyncCopy", "AsyncCursor", diff --git a/psycopg_c/psycopg_c/__init__.py b/psycopg_c/psycopg_c/__init__.py index 6bd9b8ded..ac56afa87 100644 --- a/psycopg_c/psycopg_c/__init__.py +++ b/psycopg_c/psycopg_c/__init__.py @@ -13,4 +13,4 @@ if "psycopg" not in sys.modules: "the psycopg package should be imported before psycopg_c" ) -from .version import __version__ # noqa +from .version import __version__ as __version__ # noqa diff --git a/psycopg_pool/psycopg_pool/__init__.py b/psycopg_pool/psycopg_pool/__init__.py index 529a99f3b..49b035b31 100644 --- a/psycopg_pool/psycopg_pool/__init__.py +++ b/psycopg_pool/psycopg_pool/__init__.py @@ -7,7 +7,7 @@ psycopg connection pool package from .pool import ConnectionPool from .pool_async import AsyncConnectionPool from .errors import PoolClosed, PoolTimeout, TooManyRequests -from .version import __version__ # noqa: F401 +from .version import __version__ as __version__ # noqa: F401 __all__ = [ "AsyncConnectionPool", diff --git a/tests/pool/test_pool.py b/tests/pool/test_pool.py index 6abd89553..b007aecda 100644 --- a/tests/pool/test_pool.py +++ b/tests/pool/test_pool.py @@ -20,6 +20,16 @@ else: import psycopg_pool as pool +def test_package_version(mypy): + cp = mypy.run_on_source( + """\ +from psycopg_pool import __version__ +assert __version__ +""" + ) + assert not cp.stdout + + def test_defaults(dsn): with pool.ConnectionPool(dsn) as p: assert p.min_size == p.max_size == 4 diff --git a/tests/test_module.py b/tests/test_module.py index e54f5f6c8..16740d8c2 100644 --- a/tests/test_module.py +++ b/tests/test_module.py @@ -1,5 +1,7 @@ import pytest +from psycopg._cmodule import _psycopg + @pytest.mark.parametrize( "args, kwargs, want_conninfo", @@ -28,3 +30,27 @@ def test_connect(monkeypatch, dsn, args, kwargs, want_conninfo): psycopg.connect(*args, **kwargs) assert got_conninfo == want_conninfo + + +def test_version(mypy): + cp = mypy.run_on_source( + """\ +from psycopg import __version__ +assert __version__ +""" + ) + assert not cp.stdout + + +@pytest.mark.skipif(_psycopg is None, reason="C module test") +def test_version_c(mypy): + # can be psycopg_c, psycopg_binary + cpackage = _psycopg.__name__.split(".")[0] + + cp = mypy.run_on_source( + f"""\ +from {cpackage} import __version__ +assert __version__ +""" + ) + assert not cp.stdout