Skip to content

Add lazy matchers #173

@masklinn

Description

@masklinn

See #171

This should be reasonably easy with the API changes of #116. Matchers should probably be a triple of lists of Matcher[*], where Matcher is

T = TypeVar("T")
class Matcher(abc.ABC, Generic[T]):
    @abc.abstractmethod
    def __call__(self, ua: str) -> Optional[T]:
        pass

and we can update e.g. class UserAgentMatcher(Matcher[UserAgent]), making the typing line up (hopefully).

The question is how to provide the lazy versions of the matchers:

  • add one more generated file generating a triplet of lists of lazy matchers (at which point the codegen should probably be abstracted some as it's getting really messy)
  • add a generator which yields arbitrarily applied thingie e.g.
    def user_agents(callback):
        yield callback('(GeoEvent Server) (\d+)(?:\.(\d+)(?:\.(\d+)|)|)')
        yield callback('(ArcGIS Pro)(?: (\d+)\.(\d+)\.([^ ]+)|)')
        ...
    maybe with a cache on callback somehow? Not sure there's any way that can work, might make more sense with a wrapper converting that to a list and the callbacks are just intermediate convenience?
  • generate lists of the parameters and map to a new list at runtime
  • use json? might parse faster than python file but requires re-mapping, and is eager, and might not work because it can't benefit from some optimisations (but not sure there are any optimisations to the generated modules, they create lists of function calls but there's no string sharing or key sharing or anything)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions