@@ -1882,8 +1882,7 @@ def my_meth(self, arg):
18821882 ),
18831883 )
18841884 _other_fields = ("name" , "is_dataclass" , "position" )
1885- _other_other_fields = ("locals" , "_newstyle" )
1886- _newstyle : bool | None = None
1885+ _other_other_fields = "locals"
18871886
18881887 def __init__ (
18891888 self ,
@@ -1983,36 +1982,11 @@ def postinit(
19831982 self .bases = bases
19841983 self .body = body
19851984 self .decorators = decorators
1986- self ._newstyle = newstyle
19871985 self ._metaclass = metaclass
19881986 self .position = position
19891987 self .doc_node = doc_node
19901988 self .type_params = type_params or []
19911989
1992- def _newstyle_impl (self , context : InferenceContext | None = None ):
1993- if context is None :
1994- context = InferenceContext ()
1995- if self ._newstyle is not None :
1996- return self ._newstyle
1997- for base in self .ancestors (recurs = False , context = context ):
1998- if base ._newstyle_impl (context ):
1999- self ._newstyle = True
2000- break
2001- klass = self .declared_metaclass ()
2002- # could be any callable, we'd need to infer the result of klass(name,
2003- # bases, dict). punt if it's not a class node.
2004- if klass is not None and isinstance (klass , ClassDef ):
2005- self ._newstyle = klass ._newstyle_impl (context )
2006- if self ._newstyle is None :
2007- self ._newstyle = False
2008- return self ._newstyle
2009-
2010- _newstyle = None
2011- newstyle = property (
2012- _newstyle_impl ,
2013- doc = ("Whether this is a new style class or not\n \n " ":type: bool or None" ),
2014- )
2015-
20161990 @cached_property
20171991 def blockstart_tolineno (self ):
20181992 """The line on which the beginning of this block ends.
@@ -2033,14 +2007,12 @@ def block_range(self, lineno: int) -> tuple[int, int]:
20332007 """
20342008 return self .fromlineno , self .tolineno
20352009
2036- def pytype (self ) -> Literal ["builtins.type" , "builtins.classobj" ]:
2010+ def pytype (self ) -> Literal ["builtins.type" ]:
20372011 """Get the name of the type that this node represents.
20382012
20392013 :returns: The name of the type.
20402014 """
2041- if self .newstyle :
2042- return "builtins.type"
2043- return "builtins.classobj"
2015+ return "builtins.type"
20442016
20452017 def display_type (self ) -> str :
20462018 """A human readable type of this node.
@@ -2580,7 +2552,6 @@ def _valid_getattr(node):
25802552 try :
25812553 return _valid_getattr (self .getattr ("__getattr__" , context )[0 ])
25822554 except AttributeInferenceError :
2583- # if self.newstyle: XXX cause an infinite recursion error
25842555 try :
25852556 getattribute = self .getattr ("__getattribute__" , context )[0 ]
25862557 return _valid_getattr (getattribute )
@@ -2667,16 +2638,12 @@ def mymethods(self):
26672638 def implicit_metaclass (self ):
26682639 """Get the implicit metaclass of the current class.
26692640
2670- For newstyle classes, this will return an instance of builtins.type.
2671- For oldstyle classes, it will simply return None, since there's
2672- no implicit metaclass there.
2641+ This will return an instance of builtins.type.
26732642
26742643 :returns: The metaclass.
2675- :rtype: builtins.type or None
2644+ :rtype: builtins.type
26762645 """
2677- if self .newstyle :
2678- return builtin_lookup ("type" )[1 ][0 ]
2679- return None
2646+ return builtin_lookup ("type" )[1 ][0 ]
26802647
26812648 def declared_metaclass (
26822649 self , context : InferenceContext | None = None
@@ -2799,10 +2766,6 @@ def _islots(self):
27992766 return None
28002767
28012768 def _slots (self ):
2802- if not self .newstyle :
2803- raise NotImplementedError (
2804- "The concept of slots is undefined for old-style classes."
2805- )
28062769
28072770 slots = self ._islots ()
28082771 try :
@@ -2842,11 +2805,6 @@ def grouped_slots(
28422805 else :
28432806 yield None
28442807
2845- if not self .newstyle :
2846- raise NotImplementedError (
2847- "The concept of slots is undefined for old-style classes."
2848- )
2849-
28502808 try :
28512809 mro = self .mro ()
28522810 except MroError as e :
@@ -2912,17 +2870,8 @@ def _compute_mro(self, context: InferenceContext | None = None):
29122870 if base is self :
29132871 continue
29142872
2915- try :
2916- mro = base ._compute_mro (context = context )
2917- bases_mro .append (mro )
2918- except NotImplementedError :
2919- # Some classes have in their ancestors both newstyle and
2920- # old style classes. For these we can't retrieve the .mro,
2921- # although in Python it's possible, since the class we are
2922- # currently working is in fact new style.
2923- # So, we fallback to ancestors here.
2924- ancestors = list (base .ancestors (context = context ))
2925- bases_mro .append (ancestors )
2873+ mro = base ._compute_mro (context = context )
2874+ bases_mro .append (mro )
29262875
29272876 unmerged_mro : list [list [ClassDef ]] = [[self ], * bases_mro , inferred_bases ]
29282877 unmerged_mro = clean_duplicates_mro (unmerged_mro , self , context )
0 commit comments