@@ -1882,8 +1882,7 @@ def my_meth(self, arg):
1882
1882
),
1883
1883
)
1884
1884
_other_fields = ("name" , "is_dataclass" , "position" )
1885
- _other_other_fields = ("locals" , "_newstyle" )
1886
- _newstyle : bool | None = None
1885
+ _other_other_fields = "locals"
1887
1886
1888
1887
def __init__ (
1889
1888
self ,
@@ -1983,36 +1982,11 @@ def postinit(
1983
1982
self .bases = bases
1984
1983
self .body = body
1985
1984
self .decorators = decorators
1986
- self ._newstyle = newstyle
1987
1985
self ._metaclass = metaclass
1988
1986
self .position = position
1989
1987
self .doc_node = doc_node
1990
1988
self .type_params = type_params or []
1991
1989
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
-
2016
1990
@cached_property
2017
1991
def blockstart_tolineno (self ):
2018
1992
"""The line on which the beginning of this block ends.
@@ -2033,14 +2007,12 @@ def block_range(self, lineno: int) -> tuple[int, int]:
2033
2007
"""
2034
2008
return self .fromlineno , self .tolineno
2035
2009
2036
- def pytype (self ) -> Literal ["builtins.type" , "builtins.classobj" ]:
2010
+ def pytype (self ) -> Literal ["builtins.type" ]:
2037
2011
"""Get the name of the type that this node represents.
2038
2012
2039
2013
:returns: The name of the type.
2040
2014
"""
2041
- if self .newstyle :
2042
- return "builtins.type"
2043
- return "builtins.classobj"
2015
+ return "builtins.type"
2044
2016
2045
2017
def display_type (self ) -> str :
2046
2018
"""A human readable type of this node.
@@ -2580,7 +2552,6 @@ def _valid_getattr(node):
2580
2552
try :
2581
2553
return _valid_getattr (self .getattr ("__getattr__" , context )[0 ])
2582
2554
except AttributeInferenceError :
2583
- # if self.newstyle: XXX cause an infinite recursion error
2584
2555
try :
2585
2556
getattribute = self .getattr ("__getattribute__" , context )[0 ]
2586
2557
return _valid_getattr (getattribute )
@@ -2667,16 +2638,12 @@ def mymethods(self):
2667
2638
def implicit_metaclass (self ):
2668
2639
"""Get the implicit metaclass of the current class.
2669
2640
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.
2673
2642
2674
2643
:returns: The metaclass.
2675
- :rtype: builtins.type or None
2644
+ :rtype: builtins.type
2676
2645
"""
2677
- if self .newstyle :
2678
- return builtin_lookup ("type" )[1 ][0 ]
2679
- return None
2646
+ return builtin_lookup ("type" )[1 ][0 ]
2680
2647
2681
2648
def declared_metaclass (
2682
2649
self , context : InferenceContext | None = None
@@ -2799,10 +2766,6 @@ def _islots(self):
2799
2766
return None
2800
2767
2801
2768
def _slots (self ):
2802
- if not self .newstyle :
2803
- raise NotImplementedError (
2804
- "The concept of slots is undefined for old-style classes."
2805
- )
2806
2769
2807
2770
slots = self ._islots ()
2808
2771
try :
@@ -2842,11 +2805,6 @@ def grouped_slots(
2842
2805
else :
2843
2806
yield None
2844
2807
2845
- if not self .newstyle :
2846
- raise NotImplementedError (
2847
- "The concept of slots is undefined for old-style classes."
2848
- )
2849
-
2850
2808
try :
2851
2809
mro = self .mro ()
2852
2810
except MroError as e :
@@ -2912,17 +2870,8 @@ def _compute_mro(self, context: InferenceContext | None = None):
2912
2870
if base is self :
2913
2871
continue
2914
2872
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 )
2926
2875
2927
2876
unmerged_mro : list [list [ClassDef ]] = [[self ], * bases_mro , inferred_bases ]
2928
2877
unmerged_mro = clean_duplicates_mro (unmerged_mro , self , context )
0 commit comments