[issue22434] Use named constants internally in the re module

Serhiy Storchaka report at bugs.python.org
Fri Sep 19 10:00:14 CEST 2014


Serhiy Storchaka added the comment:

Here is a patch using enums. I still think enums are superfluous here. Advanced the Enum class features (pickling, access by name, type checking) are not needed - these constants don't leaked in outer word.

> I don't see where there would be a circular dependency; the enum module
> doesn't import the re module.

Right now there is no circular dependency. But the enum module imports collections which imports a lot of other modules, some of which import other modules. In future some of indirectly imported module can import the re module.

> There is one thing that might be less convenient: defining an enum doesn't
> automatically make the values globals. But wouldn't the code be better if
> the values weren't globals?

I afraid this will make the code of parser and compiler less readable and slower. In any case the sre_constants module itself is a namespace.

----------
Added file: http://bugs.python.org/file36657/re_opcode_enums.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue22434>
_______________________________________


More information about the Python-bugs-list mailing list