Skip to content

Commit 80b4e64

Browse files
authored
feat(pylint): Add httpx as a blocked networking import (#8870)
* feat: Add httpx as a blocked networking import * chore: Update CHANGELOG.md
1 parent 69ff96c commit 80b4e64

3 files changed

Lines changed: 21 additions & 4 deletions

File tree

tools/pylint-extensions/azure-pylint-guidelines-checker/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Release History
22

3+
## 0.5.0 (unreleased)
4+
5+
- Feature: Add `httpx` as an import flagged by C4749(networking-import-outside-azure-core-transport)
6+
37
## 0.4.1 (2024-04-17)
48

59
- Bug fix for typing under TYPE_CHECKING block.

tools/pylint-extensions/azure-pylint-guidelines-checker/pylint_guidelines_checker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2376,7 +2376,7 @@ class NonCoreNetworkImport(BaseChecker):
23762376
"This import is only allowed in azure.core.pipeline.transport.",
23772377
),
23782378
}
2379-
BLOCKED_MODULES = ["aiohttp", "requests", "trio"]
2379+
BLOCKED_MODULES = ["aiohttp", "requests", "trio", "httpx"]
23802380
AZURE_CORE_TRANSPORT_NAME = "azure.core.pipeline.transport"
23812381

23822382
def visit_import(self, node):

tools/pylint-extensions/azure-pylint-guidelines-checker/tests/test_pylint_custom_plugins.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4052,18 +4052,31 @@ class TestCheckNonCoreNetworkImport(pylint.testutils.CheckerTestCase):
40524052
def test_disallowed_imports(self):
40534053
"""Check that illegal imports raise warnings"""
40544054
# Blocked import ouside of core.
4055-
import_node = astroid.extract_node("import requests")
4055+
requests_import_node = astroid.extract_node("import requests")
40564056
with self.assertAddsMessages(
40574057
pylint.testutils.MessageTest(
40584058
msg_id="networking-import-outside-azure-core-transport",
40594059
line=1,
4060-
node=import_node,
4060+
node=requests_import_node,
40614061
col_offset=0,
40624062
end_line=1,
40634063
end_col_offset=15,
40644064
)
40654065
):
4066-
self.checker.visit_import(import_node)
4066+
self.checker.visit_import(requests_import_node)
4067+
4068+
httpx_import_node = astroid.extract_node("import httpx")
4069+
with self.assertAddsMessages(
4070+
pylint.testutils.MessageTest(
4071+
msg_id="networking-import-outside-azure-core-transport",
4072+
line=1,
4073+
node=httpx_import_node,
4074+
col_offset=0,
4075+
end_line=1,
4076+
end_col_offset=12,
4077+
)
4078+
):
4079+
self.checker.visit_import(httpx_import_node)
40674080

40684081
# blocked import from outside of core.
40694082
importfrom_node = astroid.extract_node("from aiohttp import get")

0 commit comments

Comments
 (0)