You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently there's a significant amount of initialization done in __enter__ instead of __init__. This means that code will silently fail if not used with a context manager:
scene=S2COGReader('S2B_12SYJ_20200901_0_L2A')
# no errorscene.center# errors:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-77-5a7975690aa4> in <module>
----> 1 self.center
<ipython-input-43-587f5a19de47> in center(self)
41 """Dataset center + minzoom."""
42 return (
---> 43 (self.bounds[0] + self.bounds[2]) / 2,
44 (self.bounds[1] + self.bounds[3]) / 2,
45 self.minzoom,
AttributeError: 'S2COGReader' object has no attribute 'bounds'
I believe __init__ should be used for any necessary initialization of the class. __enter__ should only instantiate context-specific attributes like a file descriptor or a database cursor. Such a context really doesn't apply here, and __enter__ is essentially on there for syntactical sugar. Hence initialization should be move entirely to __init__.
The text was updated successfully, but these errors were encountered:
We built rio_tiler.io.BaseReader with only __enter__ and __exit__ to force the user to use context manager. I understand there is no need for CTX in rio-tiler-pds, mostly because we don't need to close or delete any resource. but I'd like to keep this syntax. I'm ok for moving stuff outisde the __enter__ but I'll keep the documentation as it is.
Note: because we are using attrs we don't need __init__ but we will need instead a __attrs_post_init__ method.
Currently there's a significant amount of initialization done in
__enter__
instead of__init__
. This means that code will silently fail if not used with a context manager:I believe
__init__
should be used for any necessary initialization of the class.__enter__
should only instantiate context-specific attributes like a file descriptor or a database cursor. Such a context really doesn't apply here, and__enter__
is essentially on there for syntactical sugar. Hence initialization should be move entirely to__init__
.The text was updated successfully, but these errors were encountered: