File tree 4 files changed +33
-4
lines changed 4 files changed +33
-4
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,8 @@ What's New in astroid 2.2.0?
7
7
Release Date: TBA
8
8
9
9
10
+ * Add a registry for builtin exception models. Close PyCQA/pylint#1432
11
+
10
12
* Add brain tips for `http.client`. Close PyCQA/pylint#2687
11
13
12
14
* Prevent crashing when processing ``enums`` with mixed single and double quotes.
Original file line number Diff line number Diff line change @@ -601,6 +601,9 @@ def py__dict__(self):
601
601
return _dunder_dict (self ._instance , self ._instance .instance_attrs )
602
602
603
603
604
+ # Exception instances
605
+
606
+
604
607
class ExceptionInstanceModel (InstanceModel ):
605
608
@property
606
609
def pyargs (self ):
@@ -616,6 +619,15 @@ def py__traceback__(self):
616
619
return traceback_type .instantiate_class ()
617
620
618
621
622
+ class SyntaxErrorInstanceModel (ExceptionInstanceModel ):
623
+ @property
624
+ def pytext (self ):
625
+ return node_classes .Const ("" )
626
+
627
+
628
+ BUILTIN_EXCEPTIONS = {"builtins.SyntaxError" : SyntaxErrorInstanceModel }
629
+
630
+
619
631
class DictModel (ObjectModel ):
620
632
@property
621
633
def py__class__ (self ):
Original file line number Diff line number Diff line change @@ -210,10 +210,13 @@ class ExceptionInstance(bases.Instance):
210
210
the case of .args.
211
211
"""
212
212
213
- # pylint: disable=unnecessary-lambda
214
- special_attributes = util .lazy_descriptor (
215
- lambda : objectmodel .ExceptionInstanceModel ()
216
- )
213
+ @decorators .cachedproperty
214
+ def special_attributes (self ):
215
+ qname = self .qname ()
216
+ instance = objectmodel .BUILTIN_EXCEPTIONS .get (
217
+ qname , objectmodel .ExceptionInstanceModel
218
+ )
219
+ return instance ()
217
220
218
221
219
222
class DictInstance (bases .Instance ):
Original file line number Diff line number Diff line change @@ -585,6 +585,18 @@ def test_model_py3(self):
585
585
with self .assertRaises (exceptions .InferenceError ):
586
586
next (ast_nodes [2 ].infer ())
587
587
588
+ def test_syntax_error (self ):
589
+ ast_node = builder .extract_node (
590
+ """
591
+ try:
592
+ x[42]
593
+ except SyntaxError as err:
594
+ err.text #@
595
+ """
596
+ )
597
+ inferred = next (ast_node .infer ())
598
+ assert isinstance (inferred , astroid .Const )
599
+
588
600
589
601
class DictObjectModelTest (unittest .TestCase ):
590
602
def test__class__ (self ):
You can’t perform that action at this time.
0 commit comments