Skip to content

Commit

Permalink
feat(pylint): Add httpx as a blocked networking import (#8870)
Browse files Browse the repository at this point in the history
* feat: Add httpx as a blocked networking import

* chore: Update CHANGELOG.md
  • Loading branch information
kdestin authored Aug 26, 2024
1 parent 69ff96c commit 80b4e64
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Release History

## 0.5.0 (unreleased)

- Feature: Add `httpx` as an import flagged by C4749(networking-import-outside-azure-core-transport)

## 0.4.1 (2024-04-17)

- Bug fix for typing under TYPE_CHECKING block.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2376,7 +2376,7 @@ class NonCoreNetworkImport(BaseChecker):
"This import is only allowed in azure.core.pipeline.transport.",
),
}
BLOCKED_MODULES = ["aiohttp", "requests", "trio"]
BLOCKED_MODULES = ["aiohttp", "requests", "trio", "httpx"]
AZURE_CORE_TRANSPORT_NAME = "azure.core.pipeline.transport"

def visit_import(self, node):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4052,18 +4052,31 @@ class TestCheckNonCoreNetworkImport(pylint.testutils.CheckerTestCase):
def test_disallowed_imports(self):
"""Check that illegal imports raise warnings"""
# Blocked import ouside of core.
import_node = astroid.extract_node("import requests")
requests_import_node = astroid.extract_node("import requests")
with self.assertAddsMessages(
pylint.testutils.MessageTest(
msg_id="networking-import-outside-azure-core-transport",
line=1,
node=import_node,
node=requests_import_node,
col_offset=0,
end_line=1,
end_col_offset=15,
)
):
self.checker.visit_import(import_node)
self.checker.visit_import(requests_import_node)

httpx_import_node = astroid.extract_node("import httpx")
with self.assertAddsMessages(
pylint.testutils.MessageTest(
msg_id="networking-import-outside-azure-core-transport",
line=1,
node=httpx_import_node,
col_offset=0,
end_line=1,
end_col_offset=12,
)
):
self.checker.visit_import(httpx_import_node)

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

0 comments on commit 80b4e64

Please sign in to comment.