{"id":16516883,"url":"https://github.com/alkasm/ns-deprecation","last_synced_at":"2026-05-15T05:04:36.444Z","repository":{"id":123352187,"uuid":"606650533","full_name":"alkasm/ns-deprecation","owner":"alkasm","description":"Testing ways to deprecate a namespace package","archived":false,"fork":false,"pushed_at":"2023-02-26T06:03:40.000Z","size":6,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-02T18:20:12.766Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alkasm.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-02-26T05:57:00.000Z","updated_at":"2023-02-26T06:04:36.000Z","dependencies_parsed_at":null,"dependency_job_id":"6c3266d0-300f-4fc5-a553-5293f29c0e7e","html_url":"https://github.com/alkasm/ns-deprecation","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/alkasm/ns-deprecation","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alkasm%2Fns-deprecation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alkasm%2Fns-deprecation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alkasm%2Fns-deprecation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alkasm%2Fns-deprecation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alkasm","download_url":"https://codeload.github.com/alkasm/ns-deprecation/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alkasm%2Fns-deprecation/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33054454,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-13T13:14:54.681Z","status":"online","status_checked_at":"2026-05-15T02:00:06.351Z","response_time":103,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-11T16:27:26.081Z","updated_at":"2026-05-15T05:04:36.416Z","avatar_url":"https://github.com/alkasm.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# namespace deprecation test\n\nThis is a trial to figure out how to insert a subpackage into a namespace package, with backwards compatibility and deprecation warnings.\n\n### current/\n\nHere we have a namespace package `nstest` with subpackages `pkg_a` and `pkg_b`:\n\n```python\n\u003e\u003e\u003e from nstest.pkg_a.a import a\n\u003e\u003e\u003e from nstest.pkg_b.b import b\n\u003e\u003e\u003e print(a, b)\na b\n```\n\n### future/\n\n```python\n\u003e\u003e\u003e from nstest.pkgs.pkg_a.a import a\n\u003e\u003e\u003e from nstest.pkgs.pkg_b.b import b\n\u003e\u003e\u003e print(a, b)\na b\n```\n\n### midway/\n\n```python\n\u003e\u003e\u003e from nstest.pkg_a.a import a\n\u003cstdin\u003e:2: FutureWarning: referencing `nstest.pkg_a` is deprecated; use `nstest.pkgs.pkg_a` instead\n\u003e\u003e\u003e from nstest.pkg_b.b import b\n\u003cstdin\u003e:2: FutureWarning: referencing `nstest.pkg_b` is deprecated; use `nstest.pkgs.pkg_b` instead\n\u003e\u003e\u003e print(a, b)\na b\n```\n\nAfter awhile, we can turn on hard deprecation and keep the old package name around, but only to throw a useful error:\n\n```python\n\u003e\u003e\u003e from nstest.pkg_a.a import a\nModuleNotFoundError: No module named 'nstest.pkg_a.a'. Did you mean 'nstest.pkgs.pkg_a.a'?\n```\n\n### Some ideas\n\n#### Stubbed `__init__.py`\n\nIf `pkg_a` and `pkg_b` are not namespace packages, then we can stub them out inside `nstest` and have them reference `nstest.pkgs`, e.g.\n\n```python\n# nstest/pkg_a/__init__.py\nimport warnings\nwarnings.warn(\"referencing `nstest.pkg_a` is deprecated; use `nstest.pkgs.pkg_a` instead\")\n\nfrom nstest.pkgs.pkg_a import a as a\n```\n\nBut this doesn't work for namespace packages, because they don't have an `__init__.py`.\n\n#### Stubs for every module\n\nCould instead provide stubs for _every_ module.\n\n```python\n# nstest/pkg_a/a.py\nimport warnings\nwarnings.warn(\"referencing `nstest.pkg_a` is deprecated; use `nstest.pkgs.pkg_a` instead\")\n\nfrom nstest.pkgs.pkg_a.a import *\n```\n\nDo type stubs work in this case as well?\n\nYes, they do! However, this does not work if you programmatically import via `importlib` or `__import__`. It all probably works if you simply import the module, but not if you `from module import *`, which we need to do if we want to alias that module. To alias it properly, we'd need to update `globals()` with the module's contents, and mypy does _not_ understand that.\n\n#### pkgutil-style namespace packages\n\nThis might provide another solution as well, but I haven't looked into it. Not sure how/if it would affect existing subpackages and so on.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falkasm%2Fns-deprecation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falkasm%2Fns-deprecation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falkasm%2Fns-deprecation/lists"}