You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 8496596
Browse filesBrowse the repository at this point in the historyBrowse files
Python: Replace wildcard imports with explicit imports
- Replace all 'from ... import *' with explicit symbol imports
- Add __all__ declarations to namespace packages for re-exports
- Update CODING_STANDARD.md to prohibit wildcard imports
- Maintain exported API and preserve all functionality
fixes #3605
Copy file name to clipboardExpand all lines: python/CODING_STANDARD.md
+19-4Lines changed: 19 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -403,22 +403,37 @@ If in doubt, use the link above to read much more considerations of what to do a
403
403
404
404
### Explicit Exports
405
405
406
-
> **Note:** This convention is being adopted. See [#3605](https://github.com/microsoft/agent-framework/issues/3605) for progress.
406
+
**All wildcard imports (`from ... import *`) are prohibited** in production code, including both `.py` and `.pyi` files. Always use explicit import lists to maintain clarity and avoid namespace pollution.
407
407
408
-
Define `__all__` in each module to explicitly declare the public API. Avoid using `from module import *` in `__init__.py` files as it can impact performance and makes the public API unclear:
408
+
Define `__all__` in each module to explicitly declare the public API, then import specific symbols by name:
409
409
410
410
```python
411
-
# ✅ Preferred - explicit __all__ and imports
411
+
# ✅ Preferred - explicit __all__ and named imports
412
412
__all__= ["Agent", "Message", "ChatResponse"]
413
413
414
414
from ._agents import Agent
415
415
from ._types import Message, ChatResponse
416
416
417
-
# ❌ Avoid - star imports
417
+
# ✅ For many exports, use parenthesized multi-line imports
418
+
from ._types import (
419
+
AgentResponse,
420
+
ChatResponse,
421
+
Message,
422
+
ResponseStream,
423
+
)
424
+
425
+
# ❌ Prohibited - wildcard/star imports
418
426
from ._agents import*
419
427
from ._types import*
420
428
```
421
429
430
+
**Rationale:**
431
+
-**Clarity**: Explicit imports make it clear exactly what is being exported and used
432
+
-**IDE Support**: Enables better autocomplete, go-to-definition, and refactoring
433
+
-**Type Checking**: Improves static analysis and type checker accuracy
434
+
-**Maintenance**: Makes it easier to track symbol usage and detect breaking changes
435
+
-**Performance**: Avoids unnecessary symbol resolution during module import
0 commit comments