Skip to content

Commit c94968f

Browse files
Add type guard to Instance constructor
1 parent 468ab37 commit c94968f

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

astroid/bases.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
import collections
1111
import collections.abc
1212
from collections.abc import Sequence
13-
from typing import TYPE_CHECKING, Any
13+
from typing import Any
1414

15-
from astroid import decorators
15+
from astroid import decorators, nodes
1616
from astroid.const import PY310_PLUS
1717
from astroid.context import (
1818
CallContext,
@@ -33,9 +33,6 @@
3333
helpers = lazy_import("helpers")
3434
manager = lazy_import("manager")
3535

36-
if TYPE_CHECKING:
37-
from astroid import nodes
38-
3936

4037
# TODO: check if needs special treatment
4138
BOOL_SPECIAL_METHOD = "__bool__"
@@ -293,6 +290,11 @@ class Instance(BaseInstance):
293290
# pylint: disable=unnecessary-lambda
294291
special_attributes = lazy_descriptor(lambda: objectmodel.InstanceModel())
295292

293+
def __init__(self, proxied: nodes.ClassDef) -> None:
294+
if not isinstance(proxied, nodes.ClassDef):
295+
raise TypeError
296+
super().__init__(proxied)
297+
296298
def __repr__(self):
297299
return "<Instance of {}.{} at 0x{}>".format(
298300
self._proxied.root().name, self._proxied.name, id(self)
@@ -415,9 +417,6 @@ def _infer_builtin_new(
415417
) -> collections.abc.Generator[
416418
nodes.Const | Instance | type[Uninferable], None, None
417419
]:
418-
# pylint: disable-next=import-outside-toplevel; circular import
419-
from astroid import nodes
420-
421420
if not caller.args:
422421
return
423422
# Attempt to create a constant

0 commit comments

Comments
 (0)