Title: Py313 replace pkgutil get loader for 3.14 by pattems · Pull Request #130 · python-postgres/fe · GitHub
Open Graph Title: Py313 replace pkgutil get loader for 3.14 by pattems · Pull Request #130 · python-postgres/fe
X Title: Py313 replace pkgutil get loader for 3.14 by pattems · Pull Request #130 · python-postgres/fe
Description: Three commits. 1. Replace pkgutil.get_loader for 3.14 postgresql/python/command.py does from pkgutil import get_loader as module_loader. pkgutil.get_loader was deprecated in Python 3.12 and removed in 3.14, so on 3.14 >>> import postgresql.python.command ImportError: cannot import name 'get_loader' from 'pkgutil' which also takes down postgresql.bin.pg_python (the pg_python script). On 3.12/3.13 it emits a DeprecationWarning on every -m/-C module: use. The change defines module_loader(name) on top of importlib.util.find_spec() (available since 3.4, so fine for requires-python >= 3.7), returning the spec's loader or None, which is what Execution expects. 2. Always set version; fixes pg_dotconf import postgresql/__init__.py does from .project import version_info, version, \ author as __author__, date as __date__ __version__ = version inside try/except ImportError. project.py no longer defines author or date, so the import fails after binding version and before __version__ is set; the error is swallowed. As a result, on any Python version: >>> import postgresql.bin.pg_dotconf ImportError: cannot import name '__version__' from 'postgresql' >>> from postgresql import * AttributeError: module 'postgresql' has no attribute '__author__' The change imports only version_info and version, sets __version__ after the try, and drops __author__/__date__ from __all__. 3. Fix pg_dotconf -f/--file With the import fixed, pg_dotconf -f settings.conf postgresql.conf hits NameError: name 'comment' is not defined: the loop uses bare comment and unquote instead of configfile.comment/configfile.unquote. It also tested line[pl[0].start] (the first character of the key) for the comment marker, so a commented-out setting in the settings file would have been applied. It now checks line[:pl[0].start], as configfile.alter_config() does. Testing Driving postgresql.python.command.command() directly with ['pg_python', '-C', 'module:pgcmd_ctx', '-m', 'pgcmd_main', 'a1', 'a2'] (two small throwaway modules on sys.path), plus -m no_such_module_xyz, with DeprecationWarning turned into errors: Before (f71e4b2): 3.14.3 -> ImportError on import; 3.12.13 and 3.13.14 -> DeprecationWarning: 'pkgutil.get_loader' is deprecated and slated for removal in Python 3.14. After, CPython 3.12.13, 3.13.14 and 3.14.3: main module runs as __main__ with argv ['a1', 'a2'] and the context module's globals, returns 0; the missing module raises ImportError: Python module 'no_such_module_xyz' does not exist or cannot be read as before. python -m unittest postgresql.test.test_python: OK on all three. Commits 2 and 3: import postgresql, from postgresql import *, then pg_dotconf.command(['pg_dotconf', '--stdout', '-f', 'settings.conf', 'postgresql.conf']) with a settings file holding port = 5433 and #work_mem = 64MB, and a postgresql.conf holding #port = 5432, max_connections = 100, #work_mem = 4MB: Before (f71e4b2 + commit 1): __version__ missing, star import AttributeError, import postgresql.bin.pg_dotconf ImportError (CPython 3.12.13 and 3.13.14). After commit 2 only: NameError comment in command(). After commit 3, CPython 3.12.13, 3.13.14 and 3.14.3: __version__ == '1.3.1', star import OK, output port = '5433', max_connections = 100, #work_mem = 4MB (the commented work_mem line in the settings file is skipped). python -m unittest postgresql.test.test_configfile: OK on all three.
Open Graph Description: Three commits. 1. Replace pkgutil.get_loader for 3.14 postgresql/python/command.py does from pkgutil import get_loader as module_loader. pkgutil.get_loader was deprecated in Python 3.12 and removed...
X Description: Three commits. 1. Replace pkgutil.get_loader for 3.14 postgresql/python/command.py does from pkgutil import get_loader as module_loader. pkgutil.get_loader was deprecated in Python 3.12 and removed...
Opengraph URL: https://github.com/python-postgres/fe/pull/130
X: @github
Domain: github.com
IPv4 address: 140.82.114.3
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:05f5754f-6512-ddeb-02e6-6eed4e4d12e4 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | AE2A:2D6F70:3B4C1:5353A:6B046158 |
| html-safe-nonce | f32a4b84683a4a7beb5162922c12fb5b7a99fb7b66cf9ee7a7834ebe2e7fa362 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBRTJBOjJENkY3MDozQjRDMTo1MzUzQTo2QjA0NjE1OCIsInZpc2l0b3JfaWQiOiI5NDc1NjEyMTQyNjE4NzkxMjgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | f61759720c76e513f39cba1d73594e6098089cacb54d194d6e44c9fb27eea230 |
| hovercard-subject-tag | pull_request:5026435178 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/python-postgres/fe/pull/130/files |
| twitter:image | https://avatars.githubusercontent.com/u/2626332?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/2626332?s=400&v=4 |
| og:image:alt | Three commits. 1. Replace pkgutil.get_loader for 3.14 postgresql/python/command.py does from pkgutil import get_loader as module_loader. pkgutil.get_loader was deprecated in Python 3.12 and removed... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 2d58451b4bcb73c33c67bfb6b28fb75fe6d5e279daf9b560fa4fd832f3d8c9a6 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/python-postgres/fe git https://github.com/python-postgres/fe.git |
| octolytics-dimension-user_id | 2132548 |
| octolytics-dimension-user_login | python-postgres |
| octolytics-dimension-repository_id | 100230 |
| octolytics-dimension-repository_nwo | python-postgres/fe |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 100230 |
| octolytics-dimension-repository_network_root_nwo | python-postgres/fe |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 03e114520787ad27289207f153520ef97461127c |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | no-cache |
Viewport: width=device-width