Skip to content

Remove wildcard imports in Python code #3645

@nycrat

Description

@nycrat

Description of the task

Using wildcard imports are bad practice in Python because:

  1. They add a lot of unnecessary classes and functions to the global namespace
  2. They don't work well with any Python LSPs
  3. It allows conflicting identifier names. For example, in simulated_hrvo_test.py, THE ORDER OF IMPORTS MATTERS. If you move from proto.ssl_gc_common_pb2 import Team above from proto.import_all_protos import *, the code will break since they import two different Team types. (This is also why a lot of places in the code uses from proto.ssl_gc_common_pb2 import Team as SslTeam)

A better practice is to either import as a module: import proto.import_all_protos as proto or explicitly importing specific identifiers: from proto.import_all_protos import Ball, Team. Both have their pros and cons and both types of imports currently exist in the codebase already.

Acceptance criteria

  • There are no more wildcard imports in our Python code

Blocked By

N/A

Metadata

Metadata

Assignees

Labels

Code QualityCode readability, SOLID principlesDifficulty - 3Easy and simple issues that require some context to do

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions