Skip to content

Single-underscore function not recognized as custom builtin #1906

@janlarres

Description

@janlarres

Describe the Bug

When using a __builtins__.pyi file, functions named simply _ aren't properly recognized, unlike other functions:

# test.py
gettext("a")
_("b")
# __builtins__.pyi
def gettext(message: str) -> str: ...
def _(message: str) -> str: ...
$ pyrefly check
 INFO Checking current directory with default configuration
ERROR Could not find name `_` [unknown-name]
 --> test.py:2:1
  |
2 | _("b")
  | ^
  |
 INFO 1 error

Pyright handles this correctly:

$ pyright
0 errors, 0 warnings, 0 informations

Aliasing gettext to _ is a common thing to do, so it would be useful if this were supported.

Sandbox Link

https://pyrefly.org/sandbox/?project=N4IgZglgNgpgziAXKOBDAdgEwEYHsAeAdAA4CeSIAxAAQDqMUAxrgLYzUAuunAFuwAqkATjDBRS1AMoYcBADS8IcakuqpqxVAHMYAHXQ0A7nxHVSuAK7VGGaoaEQOMBXB6pTM6rHfo1eCxycpMQQ6FoqvoIcPLjohPqUCdQAEjAeHtaWxLDUYDCoHBYiyrhgispoWHj4iEkAtNQA4jCBIqhQdRwQbEHE7Ix8jADWoeF5MDiow-XUAKpw7CIAbvlQAPocwTAAFACUnNyhcH2MgaF5QiKYvfAzMPh9DmzogYaOPLzsAJIAIgCiuXyhWKvAKdnYcAsxGIuCEgW2MEIWkIagCuGYLGyLWc1C0uE6%2BMwolCjggsQUMRWQgULUYuxmtAcTjUWGoQgskVI0VimSJ1EwEBEp3EETMliE1GwQlwhgWQn0%2Bh0HCc%2BA4210IFQGvp6DW6pA2G1IDkIDIIjEpEIXBYUAoNEE5pFlVk%2BEy6EgWiKBTJcSSkhg7B4yuIcEQAHow2bROJCLCtGGYOgw5h0XAw8x3RBPUJvbEw7lYWolqhoKhsDkMx6vV0ebhiDX0HB4ugyNz0HUqXAfdQALzUDUAZkIAEYAEwa-TGkBrNbYCzQLqNmckUgQChEspKlVqthwNA6RDUOAcIT7OoAPiPJ8PhFv%2Bg31D1u-3MEPx9P1AvV6EN9vIAAviaUxdCsABi0AwBQzrVCuAFAA

(Only applicable for extension issues) IDE Information

No response

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions