Skip to content

Making LogRecord class derivable#77

Merged
tonybaloney merged 4 commits into
microsoft:mainfrom
pamelafox:derivable
Sep 22, 2022
Merged

Making LogRecord class derivable#77
tonybaloney merged 4 commits into
microsoft:mainfrom
pamelafox:derivable

Conversation

@pamelafox

Copy link
Copy Markdown
Member

I am currently checking for differences between CPython logging module and picologging by running the CPython logging tests, and this was the first issue it found: logging.LogRecord can be a base class, picologging.LogRecord cannot. I fixed that by adding the relevant flag to tp_flags and adding a test.

@codecov-commenter

codecov-commenter commented Sep 21, 2022

Copy link
Copy Markdown

Codecov Report

Merging #77 (d2effd5) into main (76c6adb) will increase coverage by 0.38%.
The diff coverage is n/a.

@@            Coverage Diff             @@
##             main      #77      +/-   ##
==========================================
+ Coverage   88.47%   88.86%   +0.38%     
==========================================
  Files          11       11              
  Lines        2056     2056              
==========================================
+ Hits         1819     1827       +8     
+ Misses        237      229       -8     
Impacted Files Coverage Δ
src/picologging/logrecord.cxx 85.86% <ø> (ø)
src/picologging/handlers.py 94.48% <0.00%> (+1.83%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@tonybaloney tonybaloney left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add the following scenarios to the test:

  • run the constructor
  • check attribute access
  • check method execution

Copy the assertions in test_no_args() that'll cover those scenarios

@pamelafox

Copy link
Copy Markdown
Member Author

Added! I do want to flag that there is a slight inconsistency between how the logging.LogRecord constructor arguments are handled versus the picologging.LogRecord constructor. For logging.LogRecord, Python already knows exactly which positional arguments are missing. For picologging.LogRecord, it only seems to know one argument at a time.
This console session shows what I mean:

>>> import logging
>>> logging.LogRecord("hi")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: LogRecord.__init__() missing 6 required positional arguments: 'level', 'pathname', 'lineno', 'msg', 'args', and 'exc_info'
>>> import picologging
>>> picologging.LogRecord("hi")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: function missing required argument 'level' (pos 2)
>>> picologging.LogRecord("hi", 2)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: function missing required argument 'pathname' (pos 3)

I don't know 1) if it matters, or 2) how to change them to match- it's not obvious to me why the experience is different.

@tonybaloney

Copy link
Copy Markdown
Collaborator

Added! I do want to flag that there is a slight inconsistency between how the logging.LogRecord constructor arguments are handled versus the picologging.LogRecord constructor. For logging.LogRecord, Python already knows exactly which positional arguments are missing. For picologging.LogRecord, it only seems to know one argument at a time. This console session shows what I mean:

>>> import logging
>>> logging.LogRecord("hi")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: LogRecord.__init__() missing 6 required positional arguments: 'level', 'pathname', 'lineno', 'msg', 'args', and 'exc_info'
>>> import picologging
>>> picologging.LogRecord("hi")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: function missing required argument 'level' (pos 2)
>>> picologging.LogRecord("hi", 2)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: function missing required argument 'pathname' (pos 3)

I don't know 1) if it matters, or 2) how to change them to match- it's not obvious to me why the experience is different.

It doesn't really matter, it still raises the correct exception type

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants