File tree Expand file tree Collapse file tree 3 files changed +32
-33
lines changed
Expand file tree Collapse file tree 3 files changed +32
-33
lines changed Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44
55[project ]
66name = " lazimp"
7- version = " 0.0.1 "
7+ version = " 0.0.2 "
88authors = [
99 { name = " Dorian Turba" , email = " dturba.pro@protonmail.com" },
1010]
@@ -15,7 +15,7 @@ classifiers = [
1515 " Programming Language :: Python :: 3" ,
1616 " License :: OSI Approved :: MIT License" ,
1717 " Operating System :: OS Independent" ,
18- " Development Status :: 2 - Pre- Alpha" ,
18+ " Development Status :: 3 - Alpha" ,
1919 " Programming Language :: Python :: 3.10" ,
2020 " Programming Language :: Python :: 3.11" ,
2121]
Original file line number Diff line number Diff line change 1+ import collections .abc
12
3+
4+ def lazy_import (
5+ bare_import : collections .abc .Container | None = None ,
6+ sub_import : collections .abc .Mapping [str , str | None ] | None = None ,
7+ ):
8+ if bare_import is None :
9+ bare_import = set ()
10+ if sub_import is None :
11+ sub_import = {}
12+
13+ import functools
14+ import importlib
15+
16+ @functools .cache
17+ def getattr_ (name : str ):
18+ if name not in bare_import and name not in sub_import :
19+ raise AttributeError (
20+ f'module { __name__ !r} has no attribute { name !r} '
21+ ) from None
22+
23+ try :
24+ return importlib .import_module (f'.{ name } ' ,
25+ sub_import .get (name , str ))
26+ except ModuleNotFoundError :
27+ raise AttributeError (
28+ f'module { __name__ !r} has no attribute { name !r} '
29+ ) from None
30+
31+ return getattr_
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments