Dealing with conflicting names

Suppose you have a class with a method whose name is the same as animported (or built-in) type, and you want to use the type in anothermethod signature. E.g.:

  1. class Message:
  2. def bytes(self):
  3. ...
  4. def register(self, path: bytes): # error: Invalid type "mod.Message.bytes"
  5. ...

The third line elicits an error because mypy sees the argument typebytes as a reference to the method by that name. Other thanrenaming the method, a work-around is to use an alias:

  1. bytes_ = bytes
  2. class Message:
  3. def bytes(self):
  4. ...
  5. def register(self, path: bytes_):
  6. ...