New submission from Serhiy Storchaka <storchaka+cpyt...@gmail.com>:

Some modules have caches. There is a need to clear all tests before running 
tests. Brett proposed to add in all modules with caches a function with the 
standardized name which is responsible for clearing module related caches. [1]

The proposed PR adds a new function clear_caches() in the sys module. It 
iterates all imported modules and calls function __clearcache__() if it is 
defined.

    def clear_caches():
        for mod in reversed(list(sys.modules.values())):
            if hasattr(mod, '__clearcache__'):
                mod.__clearcache__()

clear_caches() will be used in test.regrtest and can be used in user code. The 
PR defines also function __clearcache__ for modules which are cleared manually 
in the current code.

This is a preliminary implementation, bikeshedding is welcome.

[1] https://mail.python.org/pipermail/python-ideas/2019-March/056165.html

----------
components: Library (Lib), Tests
messages: 339190
nosy: brett.cannon, ezio.melotti, michael.foord, serhiy.storchaka
priority: normal
severity: normal
status: open
title: Add a way to clear all caches
type: enhancement
versions: Python 3.8

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue36485>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to