-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Constructor defined after classmethod is considered to have no args in the classmethod #1727
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
Comments
Probably related: class Example:
@classmethod
def example(cls, arg1: float, arg2: str) -> Example:
return cls(arg1=arg1, arg2=arg2)
def __init__(self, arg1: float, arg2: str) -> None:
pass Reports:
But passes checks if Adding And with |
(Raising priority to normal, since this have been reported twice after the original issue.) |
+1 on this, thanks @ilevkivskyi |
+1, this is also affecting my work |
Yeah, my behavior shows that it sometimes works in the wrong order. (see #4290) |
Bumping to high-pri because this is happening frequently and the workaround is non-obvious (see #2324). |
Hello! We encountered this bug on the very first day of |
There probably isn't any particular reason why this hasn't been fixed -- other than there being a lot of other high-priority work as well. This doesn't sound like it would be very hard to fix (but probably not entirely trivial either). The core team is planning to allocate a block of time focused on fixing high-priority bugs in the next couple of months, and hopefully this gets fixed then. |
Constructor defined after classmethod was considered to have no args in the classmethod. This commit fixes that bug.
I've spent some time trying to find a solution, and here is my attempt: #5501 |
Constructor defined after classmethod was considered to have no args in the classmethod. This commit fixes that bug.
I've got a PR about to go up that fixes this as a side effect of changing the type of classmethod first arguments to be a |
@msullivan There is an existing PR. Please take a look at the questions that appeared there (interactions with fine-grained mode, plugins, forward references, generics, and overloads). |
@msullivan Forgot to add the PR number, here it is #5501 |
Currently the first argument to `__new__` and classmethods is a callable type that is constructed during semantic analysis by typechecker code (!) that looks for the `__init__`/`__new__` methods. This causes a number of problems, including not being able to call `object.__new__` in a subclass's `__new__` if it took arguments (#4190) and giving the wrong type if `__init__` appeared after the class method (#1727). Taking a `Type` instead lets us solve those problems, and postpone computing the callable version of the type until typechecking if it is needed. This also lets us drop a bunch of plugin code that tries to fix up the types of its cls arguments post-hoc, sometimes incorrectly (#5263). Fixes #1727. Fixes #4190. Fixes #5263.
Currently the first argument to `__new__` and classmethods is a callable type that is constructed during semantic analysis by typechecker code (!) that looks for the `__init__`/`__new__` methods. This causes a number of problems, including not being able to call `object.__new__` in a subclass's `__new__` if it took arguments (#4190) and giving the wrong type if `__init__` appeared after the class method (#1727). Taking a `Type` instead lets us solve those problems, and postpone computing the callable version of the type until typechecking if it is needed. This also lets us drop a bunch of plugin code that tries to fix up the types of its cls arguments post-hoc, sometimes incorrectly (#5263). Fixes #1727. Fixes #4190. Fixes #5263.
The type of
cls
withinbar()
in the following code isdef () -> Foo
unless the__init__
is moved to before theclassmethod
:The text was updated successfully, but these errors were encountered: