Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix type hint of StaticEmbedding.__init__ #3196

Merged
merged 1 commit into from
Jan 25, 2025

Conversation

altescy
Copy link
Contributor

@altescy altescy commented Jan 25, 2025

Hi there 👋
This is a small change of type annotation in StaticEmbedding.__init__: np.array -> np.ndarray

np.array | None is not evaluated correctly

>>> import typing
>>> from sentence_transformers.models.StaticEmbedding import StaticEmbedding
>>> typing.get_type_hints(StaticEmbedding.__init__)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/homebrew/Cellar/python@3.12/3.12.8/Frameworks/Python.framework/Versions/3.12/lib/python3.12/typing.py", line 2311, in get_type_hints
    hints[name] = _eval_type(value, globalns, localns, type_params)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.12/3.12.8/Frameworks/Python.framework/Versions/3.12/lib/python3.12/typing.py", line 415, in _eval_type
    return t._evaluate(globalns, localns, type_params, recursive_guard=recursive_guard)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.12/3.12.8/Frameworks/Python.framework/Versions/3.12/lib/python3.12/typing.py", line 947, in _evaluate
    eval(self.__forward_code__, globalns, localns),
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<string>", line 1, in <module>
TypeError: unsupported operand type(s) for |: 'builtin_function_or_method' and 'torch._C._TensorMeta'

@tomaarsen
Copy link
Collaborator

Hello!

Well spotted! I can reproduce the issue, and your fix works for me locally as well.
Thanks a bunch!

  • Tom Aarsen

@tomaarsen tomaarsen merged commit db6ce94 into UKPLab:master Jan 25, 2025
9 checks passed
@altescy altescy deleted the fix-static-embedding-typehints branch January 25, 2025 13:13
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