Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SocketPoolConstants typo #204

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions adafruit_esp32spi/adafruit_esp32spi_socketpool.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
_global_socketpool = {}


class SocketPoolContants: # pylint: disable=too-few-public-methods
class SocketPoolConstants: # pylint: disable=too-few-public-methods
"""Helper class for the constants that are needed everywhere"""

SOCK_STREAM = const(0)
Expand All @@ -40,7 +40,7 @@ class SocketPoolContants: # pylint: disable=too-few-public-methods
MAX_PACKET = const(4000)


class SocketPool(SocketPoolContants):
class SocketPool(SocketPoolConstants):
"""ESP32SPI SocketPool library"""

def __new__(cls, iface: ESP_SPIcontrol):
Expand All @@ -60,12 +60,12 @@ def getaddrinfo( # pylint: disable=too-many-arguments,unused-argument
if not isinstance(port, int):
raise ValueError("Port must be an integer")
ipaddr = self._interface.get_host_by_name(host)
return [(SocketPoolContants.AF_INET, socktype, proto, "", (ipaddr, port))]
return [(SocketPoolConstants.AF_INET, socktype, proto, "", (ipaddr, port))]

def socket( # pylint: disable=redefined-builtin
self,
family=SocketPoolContants.AF_INET,
type=SocketPoolContants.SOCK_STREAM,
family=SocketPoolConstants.AF_INET,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dhalbert I'm open to suggestions, but this is why the superclass was added. Since we are in the class, it's not defined and thus this line will error on import:
image
ignore the line number in the image, it's this one

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. But what about something like this? This works:

class ConstantsTest:
    A = 1
    B = 2

    def f(self, a=A, b=B):
        pass

The unqualified name works.

This actually is more complicated. In CPython, AF_INET, etc. are defined at the module level, not inside the Socket class. I can't remember why we defined them as class constants in SocketPool instead of in socketpool.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, I can do a commination of both...

I'm assuming they are in SocketPool, since that's where they were when ESP32SPI was created and so when socketpool.SocketPool was created if followed suit?

type=SocketPoolConstants.SOCK_STREAM,
proto=0,
fileno=None,
):
Expand Down
Loading