Skip to content

0.920: Calling function named "_" is not allowed #11774

Closed
@jolaf

Description

@jolaf

The following code:

#from gettext import translation
#from typing import TYPE_CHECKING

#if TYPE_CHECKING:
def _(s: str) -> str: # stub for gettext string wrapper
    return s

#translation('Test').install()

print(_("test"))

produces the following output:

$ mypy test.py
test.py:10:7: error: Calling function named "_" is not allowed  [misc]
    print(_("test"))
          ^
Found 1 error in 1 file (checked 1 source file)

$ mypy --version
mypy 0.920

$ python3 --version
Python 3.8.10

$ cat /etc/issue
Ubuntu 20.04.3 LTS \n \l

$ uname -a
Linux ubuntu 5.4.0-91-generic #102-Ubuntu SMP Fri Nov 5 16:31:28 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

Some lines of code in the test are commented as test would now work without proper gettext configuration.
Those lines show how a gettext-using code typically looks.

_ is a standard function name for gettext, created by translation().install(), it should be usable correctly.

If the error is really reasonable, at least there should be an option to turn it off.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions