Skip to content

Suggestion: Add Stub Files/Library definitions #214

@Benargee

Description

@Benargee

More info https://typing.python.org/en/latest/guides/writing_stubs.html

Since most of the code in this library is written in C for perfomance, it doesn't seem to get parsed for use with systems such as intellisense.

I am able to generate my own, but that seems less convenient than if it were to be generated and edited by maintainers.

I was able to use pypy to generate and detect definitions.
with the commands

pip install mypy
stubgen -m pyahocorasick -o typings/

I generated the file typings/ahocorasick.pyi

from _typeshed import Incomplete
from typing import Any

AHOCORASICK: int
EMPTY: int
KEY_SEQUENCE: int
KEY_STRING: int
MATCH_AT_LEAST_PREFIX: int
MATCH_AT_MOST_PREFIX: int
MATCH_EXACT_LENGTH: int
STORE_ANY: int
STORE_INTS: int
STORE_LENGTH: int
TRIE: int
unicode: int

class Automaton:
    kind: Incomplete
    store: Incomplete
    @classmethod
    def __init__(cls, *args, **kwargs) -> None: ...
    def add_word(self) -> Any: ...
    def clear(self) -> Any: ...
    def dump(self) -> Any: ...
    def exists(self, key) -> boolean: ...
    def find_all(self, *args, **kwargs): ...
    def get(self, *args, **kwargs): ...
    def get_stats(self) -> dict: ...
    def items(self, *args, **kwargs): ...
    def iter(self, *args, **kwargs): ...
    def iter_long(self, *args, **kwargs): ...
    def keys(self, *args, **kwargs): ...
    def longest_prefix(self, string) -> Any: ...
    def make_automaton(self) -> Any: ...
    def match(self, key) -> bool: ...
    def pop(self, word) -> Any: ...
    def remove_word(self, word) -> bool: ...
    def save(self, path, serializer) -> Any: ...
    def values(self, *args, **kwargs): ...
    def __contains__(self, other) -> bool: ...
    def __iter__(self): ...
    def __len__(self) -> int: ...
    def __reduce__(self) -> Any: ...
    def __sizeof__(self) -> int: ...

def load(path, deserializer) -> Any: ...

It should be possible to integrate into the build process and include some more verbose type definitions and method descriptions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions