diff --git a/refurb/checks/common.py b/refurb/checks/common.py index c39b908..823fd9e 100644 --- a/refurb/checks/common.py +++ b/refurb/checks/common.py @@ -732,6 +732,7 @@ def mypy_type_to_python_type(ty: Type | SymbolNode | None) -> type | None: "collections.abc.Mapping", "collections.abc.MutableMapping", "collections.defaultdict", + "os._Environ", "typing.Mapping", "typing.MutableMapping", ) diff --git a/refurb/checks/readability/no_copy_with_merge.py b/refurb/checks/readability/no_copy_with_merge.py index c8a4f58..a69e13e 100644 --- a/refurb/checks/readability/no_copy_with_merge.py +++ b/refurb/checks/readability/no_copy_with_merge.py @@ -45,7 +45,7 @@ def check_expr(expr: Expression, errors: list[Error]) -> None: case CallExpr( callee=MemberExpr(expr=lhs, name="copy"), args=[], - ) if is_same_type(get_mypy_type(lhs), dict, set): + ) if is_same_type(get_mypy_type(lhs), dict, set, "os._Environ"): msg = f"Replace `{stringify(lhs)}.copy()` with `{stringify(lhs)}`" errors.append(ErrorInfo.from_node(expr, msg)) diff --git a/test/data/err_173.py b/test/data/err_173.py index 24d9143..7264a92 100644 --- a/test/data/err_173.py +++ b/test/data/err_173.py @@ -57,6 +57,11 @@ def mutable_mapping_test(m: MutableMapping[str, str]): _ = dict(**m) +import os + +_ = dict(**os.environ) + + # these should not _ = {} diff --git a/test/data/err_173.txt b/test/data/err_173.txt index 8eb0e9b..0808811 100644 --- a/test/data/err_173.txt +++ b/test/data/err_173.txt @@ -24,3 +24,4 @@ test/data/err_173.py:43:5 [FURB173]: Replace `dict(**x, **{})` with `x | {}` test/data/err_173.py:48:5 [FURB173]: Replace `{**Wrapper().d, **x}` with `Wrapper().d | x` test/data/err_173.py:54:9 [FURB173]: Replace `dict(**m)` with `{**m}` test/data/err_173.py:57:9 [FURB173]: Replace `dict(**m)` with `{**m}` +test/data/err_173.py:62:5 [FURB173]: Replace `dict(**os.environ)` with `{**os.environ}` diff --git a/test/data/err_185.py b/test/data/err_185.py index 5e3cf06..409b358 100644 --- a/test/data/err_185.py +++ b/test/data/err_185.py @@ -17,6 +17,10 @@ class C: _ = C().d.copy() | {} +import os + +_ = os.environ.copy() | {} + # these should not diff --git a/test/data/err_185.txt b/test/data/err_185.txt index 5337438..3d160a7 100644 --- a/test/data/err_185.txt +++ b/test/data/err_185.txt @@ -5,3 +5,4 @@ test/data/err_185.py:9:13 [FURB185]: Replace `y.copy()` with `y` test/data/err_185.py:11:5 [FURB185]: Replace `x.copy()` with `x` test/data/err_185.py:11:21 [FURB185]: Replace `x.copy()` with `x` test/data/err_185.py:18:5 [FURB185]: Replace `C().d.copy()` with `C().d` +test/data/err_185.py:22:5 [FURB185]: Replace `os.environ.copy()` with `os.environ`