Skip to content

Conversation

@vsajip
Copy link
Member

@vsajip vsajip commented Jun 5, 2017

No description provided.

@vsajip vsajip self-assigned this Jun 5, 2017
@vsajip vsajip requested a review from pitrou June 5, 2017 12:42

.. versionadded:: 3.2

.. versionadded:: 3.7
Copy link
Member

Choose a reason for hiding this comment

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

That should probably be a versionchanged.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

def test_pickling(self):
for name in ('', 'root', 'foo', 'foo.bar', 'baz.bar'):
logger = logging.getLogger(name)
s = pickle.dumps(logger)
Copy link
Member

Choose a reason for hiding this comment

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

Please test it for all protocols:

for proto in range(pickle.HIGHEST_PROTOCOL + 1):
    s = pickle.dumps(logger, proto)

Logger.__init__(self, "root", level)

def __reduce__(self):
return getLogger, ('',)
Copy link
Member

Choose a reason for hiding this comment

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

Maybe without arguments at all?

return getLogger, ()

def __reduce__(self):
# In general, only the root logger will not be accessible via its name.
# However, the root logger's class has its own __reduce__ method.
if getLogger(self.name) is not self:
Copy link
Member

Choose a reason for hiding this comment

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

This implicitly creates the global logger with name self.name. Is it okay?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't see a problem with it.

# In general, only the root logger will not be accessible via its name.
# However, the root logger's class has its own __reduce__ method.
if getLogger(self.name) is not self:
raise pickle.PicklingError('logger cannot be pickled')
Copy link
Member

Choose a reason for hiding this comment

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

The pickle module is used only here. It isn't used if pickling is not involved. May be make an exception from PEP 8 and import it locally?

self.assertRaises(TypeError, logging.getLogger, any)
self.assertRaises(TypeError, logging.getLogger, b'foo')

def test_pickling(self):
Copy link
Member

Choose a reason for hiding this comment

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

__reduce__ is used also in the copy module. Maybe add tests for copy.copy() and copy.deepcopy()? Even unpickleable loggers can be copied if add special __copy__ and __deepcopy__ methods or register the classes with copyreg.pickle().

Copy link
Member Author

@vsajip vsajip Jun 5, 2017

Choose a reason for hiding this comment

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

Loggers are singletons, so copy operations shouldn't actually make copies, anyway. Seems like a separate issue (or at least use case).

self.assertRaises(TypeError, logging.getLogger, b'foo')

def test_pickling(self):
for name in ('', 'root', 'foo', 'foo.bar', 'baz.bar'):
Copy link
Member

Choose a reason for hiding this comment

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

Is self.logger pickleable? If not, it may make sense to add an explicit test for this.

Copy link
Member Author

@vsajip vsajip Jun 5, 2017

Choose a reason for hiding this comment

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

No, it's not pickleable, as it's created using Logger.__init__(), which users are not supposed to use.

Copy link
Member

Choose a reason for hiding this comment

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

It is created via Logger constructor, not via getLogger(). logging.Logger('blah') is not logging.getLogger('blah').

Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

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

LGTM.

@serhiy-storchaka
Copy link
Member

Ah, just please add a Misc/NEWS entry.

zooba and others added 10 commits June 5, 2017 15:54
…codes on Windows (#1924)

* bpo-30557: faulthandler now correctly filters and displays exception codes on Windows

* Adds test for non-fatal exceptions.

* Adds bpo number to comment.
Also weakens the 'should this be run?' regex to allow all builds when .travis.yml changes.
GH-1439)

Several class attributes have been added to calendar.HTMLCalendar that allow customization of the CSS classes used in the resulting HTML. This can be done by subclasses HTMLCalendar and overwriting those class attributes (Patch by Oz Tiram).
* Simplify X.509 extension handling code

The previous implementation had grown organically over time, as OpenSSL's API evolved.

* Delete even more code
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.

8 participants