qntm / greenery

Regular expression manipulation library
http://qntm.org/greenery
MIT License
311 stars 40 forks source link

V4, drop `greenery.fsm`, overhauled API #67

Closed qntm closed 1 year ago

qntm commented 1 year ago

This is a complete overhaul of greenery.

qntm commented 1 year ago

Aside: what the heck is up with Python's module exports behaviour? There's seriously no way at all to prevent everything from being exported, even if the importer didn't specifically import it? This is completely bananas... JavaScript's system is far superior...

rwe commented 1 year ago

Aside: what the heck is up with Python's module exports behaviour? There's seriously no way at all to prevent everything from being exported, even if the importer didn't specifically import it?

I agree with your sentiment :)

In Python, the default is to export everything except in these cases:

The default behaviour is kinda similar to each module declaring something like:

__all__ = [name for name in globals().keys() if not name.startswith('_')]

But that includes everything you've imported, too.

Usually, you want to define __all__ = ("…"). My habit is typically to do that for every module/file:

class Pattern:
  ...

__all__ = (
  'Pattern',
  'parse_pattern',
  'ParseError',
  # …
)

Importantly, without unusual temporary-scoping jiggery-pokery, it's not straightforward to prevent someone manually importing something. Which is a nightmare for interface maintenance, unfortunately.