Skip to content

Commit d695829

Browse files
committed
fix: fixed #982 missing exposed AtomCategory
The lazy loading of AtomCategory could sometimes lead to un-exposed classes. Now we forcefully import sisl.geom to ensure the categories are added to AtomCategory. Additionally a small error is now raised for incorrect arguments.
1 parent 401721e commit d695829

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

changes/982.fix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed AtomCategory usage when sisl.geom hasn't been imported

src/sisl/__init__.py

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090

9191
from ._core import *
9292

93+
9394
# Import warning classes
9495
# We currently do not import warn and info
9596
# as they are too generic names in case one does from sisl import *
@@ -133,6 +134,11 @@
133134
SileBin,
134135
)
135136

137+
# We need to pre-import geom, because
138+
# The categories are necessary to be exposed (for sub-class handling).
139+
# Therefore lazy-loading of this module is not possible.
140+
from . import geom
141+
136142
# Allow geometry to register siles
137143
# Ensure BaseSile works as a str
138144
# We have to do it after loading BaseSile and Geometry
@@ -167,18 +173,6 @@
167173
def __getattr__(attr):
168174
"""Enables simpler access of sub-modules, without having to import them"""
169175

170-
# One can test that this is only ever called once
171-
# per sub-module.
172-
# Insert a print statement, and you'll see that:
173-
# import sisl
174-
# sisl.geom
175-
# sisl.geom
176-
# will only print *once*.
177-
178-
if attr == "geom":
179-
import sisl.geom as geom
180-
181-
return geom
182176
if attr == "io":
183177
import sisl.io as io
184178

@@ -211,10 +205,7 @@ def __getattr__(attr):
211205
import sisl.unit as unit
212206

213207
return unit
214-
if attr == "C":
215-
import sisl.constant as C
216208

217-
return constant
218209
if attr == "constant":
219210
import sisl.constant as constant
220211

src/sisl/geom/_category/_coord.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,14 @@ def func(a, b):
222222
spec, sdir = key.split("_")
223223
else:
224224
sdir, op = key.split("_")
225+
if not hasattr(operator, op):
226+
raise ValueError(
227+
f"{self.__class__.__name__} could not determine the "
228+
f"operations for {key}. "
229+
"A single value for this without an operator is ill-defined. "
230+
"Please define an operator."
231+
)
232+
225233
elif value.size == 2:
226234
sdir = key
227235
else:
@@ -346,7 +354,7 @@ def _apply_key(k, v):
346354
return AtomXYZ(**{key: interval}, **new_kwargs)
347355
elif len(interval) != 0:
348356
raise ValueError(
349-
f"{cls.__name__} non-keyword argumest must be 1 tuple, or 2 values"
357+
f"{cls.__name__} non-keyword argument must be 1 tuple, or 2 values"
350358
)
351359
return AtomXYZ(**new_kwargs)
352360

0 commit comments

Comments
 (0)