Describe the Bug
When I enable the unannotated-parameter error in scipy-stubs (scipy/scipy-stubs#1262), 17 errors are reported (gh action log) for the first parameter of classmethods or __new__ methods if its name isn't cls
Repro
class A:
def __new__(cls, a: int) -> A: ... # ✔️
class B:
def __new__(_cls, a: int) -> B: ... # ❌ `__new__` is missing an annotation for parameter `_cls`
(sandbox)
I'd rather just name them cls, but I'm not able to, because then it wouldn't match the runtime name (i.e., stubtest will complain).
And although it's not an issue for scipy-stubs, I also noticed that this is also the case for self parameters of instance methods (sandbox).
The opposite also seems to be the case, i.e. non-instance method parameters called self or cls without annotation, regardless of position, will not be reported as unannotated. For example the following will be accepted:
def f(a: str, self, cls, b: int) -> None: ... # ✔️
(sandbox)
Sandbox Link
https://pyrefly.org/sandbox/?project=N4IgZglgNgpgziAXKOBDAdgEwEYHsAeAdAA4CeSIAxlKnHAAQCCiAOuvR-ZjGPQPp90MAO4CAFNTgAaeqkT0I6AC4BKegFoAfE3mE9bNtVoMAQq3aduvAUNF8xfSTLkLlarfTP09hNiCkgAK5K0HAk5IggAMT0AKohUBBKpPRggeiUIbjocAZYPKm4AE4AtqhKgoEl2DBFYvjyiqoa2nBKReac9EUwSoFF7GAsIAByVTUd9MD4AL7DfgFkPWBQpIRKuCVQFDEACqTLq-RoWHj49JTZkADm-eUQ2b7oMQDKMDD0ABZKSsRwiAB6AFLHirQjFa4AmDoAGYXCUOAAy7oG53LIwwpFWQAN1Q0FQ2FgFyuEFuRXu2XouGI6LCbDISk%2B2XU2NqcAe7AAvPRhgBmQgARgALPN0GwANq1IrFOAAXTYEBKxESlCS6gwKW5wylxVF6Qw6FwSnKMEw6mIqHJJV6tXoWpAOqKevQBqNJrNPT6AztPIdRWlTpAfhmAVQmQgrIAYtAYBQQSs1hstiAZkA
(Only applicable for extension issues) IDE Information
No response
Describe the Bug
When I enable the
unannotated-parametererror in scipy-stubs (scipy/scipy-stubs#1262), 17 errors are reported (gh action log) for the first parameter of classmethods or__new__methods if its name isn'tclsRepro
(sandbox)
I'd rather just name them
cls, but I'm not able to, because then it wouldn't match the runtime name (i.e., stubtest will complain).And although it's not an issue for scipy-stubs, I also noticed that this is also the case for
selfparameters of instance methods (sandbox).The opposite also seems to be the case, i.e. non-instance method parameters called
selforclswithout annotation, regardless of position, will not be reported as unannotated. For example the following will be accepted:(sandbox)
Sandbox Link
https://pyrefly.org/sandbox/?project=N4IgZglgNgpgziAXKOBDAdgEwEYHsAeAdAA4CeSIAxlKnHAAQCCiAOuvR-ZjGPQPp90MAO4CAFNTgAaeqkT0I6AC4BKegFoAfE3mE9bNtVoMAQq3aduvAUNF8xfSTLkLlarfTP09hNiCkgAK5K0HAk5IggAMT0AKohUBBKpPRggeiUIbjocAZYPKm4AE4AtqhKgoEl2DBFYvjyiqoa2nBKReac9EUwSoFF7GAsIAByVTUd9MD4AL7DfgFkPWBQpIRKuCVQFDEACqTLq-RoWHj49JTZkADm-eUQ2b7oMQDKMDD0ABZKSsRwiAB6AFLHirQjFa4AmDoAGYXCUOAAy7oG53LIwwpFWQAN1Q0FQ2FgFyuEFuRXu2XouGI6LCbDISk%2B2XU2NqcAe7AAvPRhgBmQgARgALPN0GwANq1IrFOAAXTYEBKxESlCS6gwKW5wylxVF6Qw6FwSnKMEw6mIqHJJV6tXoWpAOqKevQBqNJrNPT6AztPIdRWlTpAfhmAVQmQgrIAYtAYBQQSs1hstiAZkA
(Only applicable for extension issues) IDE Information
No response