Skip to content

Instantly share code, notes, and snippets.

@sloria
Last active December 19, 2015 04:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sloria/5895732 to your computer and use it in GitHub Desktop.
Save sloria/5895732 to your computer and use it in GitHub Desktop.
_DEFAULT_PORT = 1234
class SomeProtocol:
...
def __enter__(self):
self._client = socket()
self._client.connect(
(self.host,
self.port or _DEFAULT_PORT)
)
return self
# If you want to subclass SomeProtocol, you would have to overwrite every method!
# Better
class SomeProtocol:
_default_port = 1234
...
def __enter__(self):
self._client = socket()
self._client.connect(
(self.host,
self.port or self._default_port))
@danriti
Copy link

danriti commented Feb 28, 2014

@sloria, looks like you got a typo on line 12?

edit: looks like another type on line 14:

would have to overwrite very method!

Should very be every?

@sloria
Copy link
Author

sloria commented Feb 28, 2014

Fixed. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment