-
Notifications
You must be signed in to change notification settings - Fork 651
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FIX-#4582: Inherit custom log layer #4583
FIX-#4582: Inherit custom log layer #4583
Conversation
Signed-off-by: Vasily Litvinov <fam1ly.n4me@yandex.ru>
e4d684d
to
7113296
Compare
Codecov Report
@@ Coverage Diff @@
## master #4583 +/- ##
==========================================
+ Coverage 86.55% 89.60% +3.04%
==========================================
Files 230 231 +1
Lines 18435 18714 +279
==========================================
+ Hits 15957 16768 +811
+ Misses 2478 1946 -532
📣 Codecov can now indicate which changes are the most critical in Pull Requests. Learn more |
@classmethod | ||
def __init_subclass__( | ||
cls, | ||
modin_layer: str = "PANDAS-API", | ||
modin_layer: Optional[str] = None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we change Line 39 to be modin_layer: str = _modin_logging_layer
? Does that work in Python? Then just adding cls._modin_logging_layer = modin_layer
will fix this issue?
If not, can we also update the function comment to reflect the Optional[str] = None
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@naren-ponder I think the Pythonic way here is to default to None
, I don't think what you describe will work because cls
is not in scope in the signature.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@devin-petersohn Makes sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This won't work, but for the different reason.
In Python, default values are computed once at function declaration, so all instances of __init_subclass__
would get the default value as "PANDAS-API"
, effectively not achieving what this PR aims to achieve.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, but will wait for @naren-ponder to agree.
@classmethod | ||
def __init_subclass__( | ||
cls, | ||
modin_layer: str = "PANDAS-API", | ||
modin_layer: Optional[str] = None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@naren-ponder I think the Pythonic way here is to default to None
, I don't think what you describe will work because cls
is not in scope in the signature.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🚢
@classmethod | ||
def __init_subclass__( | ||
cls, | ||
modin_layer: str = "PANDAS-API", | ||
modin_layer: Optional[str] = None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@devin-petersohn Makes sense.
@@ -31,10 +31,12 @@ class ClassLogger: | |||
This mixin must go first in class bases declaration to have the desired effect. | |||
""" | |||
|
|||
_modin_logging_layer = "PANDAS-API" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can move this to a constant at the top of the file and it should work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you mean declare the string as a constant outside of the class (and re-use it in this line to set the variable) then yes, sure, it will work. But why?..
Unless we want to re-use the same constant in the @enable_logging
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, was responding to the comment here: #4583 (comment)
I thought you were saying this didn't work as we wanted it to, my mistake. Is this ok to merge?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unless you want me to extract this constant (which I don't see much value in, TBH), it should be good to go.
3961336
@devin-petersohn @naren-ponder I had to merge to solve the conflict, please re-approve and let's merge the thing if no objections. |
super().__init_subclass__(**kwargs) | ||
enable_logging(modin_layer, class_name, log_level)(cls) | ||
cls._modin_logging_layer = modin_layer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this change the _modin_logging_layer
for all children of ClassLogger
or just the children of ClassLogger
and class Foo(ClassLogger)
? For example, if there are classes:
Foo(ClassLogger, modin_layer="Custom")
, Bar(Foo)
and Other(ClassLogger)
, is Other
guaranteed to have modin_layer="PANDAS-API"
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it should be doing this way. The logic here is:
- Take the layer from declaration, but...
- If not specified, take from the class object (not instance! we don't have instances here yet, as it's the time of defining the class type)
- Class object at the time of construction won't have its own
_modin_layer
set up, so it would take one from the parent class, effectively inheriting - Then, at the end we assign a new value in case someone has actually overridden the layer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Signed-off-by: Vasily Litvinov fam1ly.n4me@yandex.ru
What do these changes do?
Fix inheritance of custom log layer. It's still possible to use
PANDAS-API
log layer in subclasses, but to do so one has to set it explicitly.flake8 modin/ asv_bench/benchmarks scripts/doc_checker.py
black --check modin/ asv_bench/benchmarks scripts/doc_checker.py
git commit -s
docs/development/architecture.rst
is up-to-date