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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Return type problem in text transformation functions #189

Closed
Antoine-Prieur opened this issue Feb 8, 2022 · 1 comment
Closed
Labels
bug Something isn't working

Comments

@Antoine-Prieur
Copy link

馃悰 Bug

Hello, there seems to be a type issue in the text transformations functions in the augly/text/functional.py file. Indeed, these functions can take a string or a list of strings as inputs, and return a new string or list of strings based on the input type.

textaugs.simulate_typos(["hello"])  # returns a list of strings
textaugs.simulate_typos("hello")  # returns a string

However, all the functions are defined as :

def change_case(
    texts: Union[str, List[str]],
    ...
) -> List[str]:
    pass

Expected behavior

Is it possible to change the types of the functions as something like this to solve this issue :

from typing import TypeVar

T = TypeVar("T", str, List[str])
def change_case(
    texts: T,
    ...
) -> T:
    pass

Environment

  • AugLy Version: 0.2.1
  • Python version: 3.8.5
@zpapakipos zpapakipos added the bug Something isn't working label Feb 15, 2022
@zpapakipos
Copy link
Contributor

Hi @Antoine-Prieur, thanks for pointing this out! You're right that the text augmentations all can take in Union[str, List[str]] and then output the same, so we should change the type signatures to match. I'll start a PR to fix this :)

zpapakipos added a commit to zpapakipos/AugLy that referenced this issue Feb 21, 2022
Summary:
## Related Issue
Fixes facebookresearch#189

- [x] I have read CONTRIBUTING.md to understand how to contribute to this repository :)

Fixing the text augmentations' return types -- the output type is the same type as the input, which can be either a `str` or a `List[str]`.

## Unit Tests
See the `test_python` workflow.

Pull Request resolved: facebookresearch#191

Differential Revision: D34340331

Pulled By: zpapakipos

fbshipit-source-id: 87b6b2fe6f8e97bcc534b98326f0079153c49858
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants