Skip to content

Commit

Permalink
Fix UnicodeDecodeError.object inferred as str instead of bytes (#…
Browse files Browse the repository at this point in the history
…2358) (#2373)

(cherry picked from commit 73afab5)

Co-authored-by: JulianJvn <[email protected]>
  • Loading branch information
github-actions[bot] and JulianJvn authored Feb 4, 2024
1 parent 80a556d commit 3e16c95
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ What's New in astroid 3.0.3?
============================
Release date: TBA


* Fix type of ``UnicodeDecodeError.object`` inferred as ``str`` instead of ``bytes``.

Closes pylint-dev/pylint#9342

* Fix ``no-member`` false positives for ``args`` and ``kwargs`` on ``ParamSpec`` under Python 3.12.

Closes pylint-dev/pylint#9401
Expand Down
2 changes: 1 addition & 1 deletion astroid/interpreter/objectmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@ def attr_path(self):
class UnicodeDecodeErrorInstanceModel(ExceptionInstanceModel):
@property
def attr_object(self):
return node_classes.Const("")
return node_classes.Const(b"")


BUILTIN_EXCEPTIONS = {
Expand Down
5 changes: 3 additions & 2 deletions tests/test_object_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -742,13 +742,14 @@ def test_oserror(self) -> None:
def test_unicodedecodeerror(self) -> None:
code = """
try:
raise UnicodeDecodeError("utf-8", "blob", 0, 1, "reason")
raise UnicodeDecodeError("utf-8", b"blob", 0, 1, "reason")
except UnicodeDecodeError as error:
error.object[:1] #@
error.object #@
"""
node = builder.extract_node(code)
inferred = next(node.infer())
assert isinstance(inferred, astroid.Const)
assert inferred.value == b""

def test_import_error(self) -> None:
ast_nodes = builder.extract_node(
Expand Down

0 comments on commit 3e16c95

Please sign in to comment.