Skip to content

Increase typing coverage #738

Open
Samoed wants to merge 8 commits intounum-cloud:main-devfrom
Samoed:typing
Open

Increase typing coverage #738
Samoed wants to merge 8 commits intounum-cloud:main-devfrom
Samoed:typing

Conversation

@Samoed
Copy link
Copy Markdown

@Samoed Samoed commented Mar 29, 2026

Make library fully typechexked. Integrate mypy typcheking for this. Not sure how much it is correct, because there is no tests. Maybe would be better to create tests firstly

# Conflicts:
#	pyproject.toml
#	python/usearch/__init__.py
#	python/usearch/index.py
setup.py Outdated
install_requires = [
"numpy",
"tqdm",
"ucall",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's avoid this dependency

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ucall is used a lot inside library. Is it expected to be an optional dependency?

Comment on lines +30 to +41
signature_i8args = types.float32(
types.CPointer(types.int8), types.CPointer(types.int8)
)
signature_f16args = types.float32(
types.CPointer(types.float16), types.CPointer(types.float16)
)
signature_f32args = types.float32(
types.CPointer(types.float32), types.CPointer(types.float32)
)
signature_f64args = types.float32(
types.CPointer(types.float64), types.CPointer(types.float64)
)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our lines are 120 lines wide - surprised that this is warping 🤔

@Samoed
Copy link
Copy Markdown
Author

Samoed commented Apr 6, 2026

When I tried to build this on mac I got error

      error: invalid argument '-std=c++17' not allowed with 'C'
      error: command '/usr/bin/cc' failed with exit code 1

and I fixed it with

from setuptools.command.build_ext import build_ext as _build_ext

# Flags that are only valid for C++ compilation
cpp_only_flags = {"-std=c++17", "/std:c++17"}


class MixedBuildExt(_build_ext):
    """Build extension that applies C++-only flags only to C++ source files."""

    def build_extension(self, ext):
        original_compile = self.compiler.compile

        def patched_compile(sources, **kwargs):
            c_sources = [s for s in sources if not s.endswith((".cpp", ".cxx", ".cc"))]
            cpp_sources = [s for s in sources if s.endswith((".cpp", ".cxx", ".cc"))]
            objects = []
            extra_args = kwargs.get("extra_postargs", [])
            if c_sources:
                c_kwargs = dict(kwargs)
                c_kwargs["extra_postargs"] = [f for f in extra_args if f not in cpp_only_flags]
                objects += original_compile(c_sources, **c_kwargs)
            if cpp_sources:
                objects += original_compile(cpp_sources, **kwargs)
            return objects

        self.compiler.compile = patched_compile
        try:
            _build_ext.build_extension(self, ext)
        finally:
            self.compiler.compile = original_compile

setup(
    ...,
    cmdclass={"build_ext": MixedBuildExt},
)

Not sure if it is good (I asked to fix claude), but I thought you might be interested

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants