Skip to content

Handle family passed as keyword argument - #75

Merged
miketheman merged 4 commits into
miketheman:mainfrom
emontnemery:patch-1
Dec 20, 2021
Merged

miketheman merged 4 commits into
miketheman:mainfrom
emontnemery:patch-1

Conversation

@emontnemery

@emontnemery emontnemery commented Sep 1, 2021 •

Copy link
Copy Markdown
Contributor

Handle family passed as keyword argument to socket constructor

@emontnemery

emontnemery commented Oct 5, 2021 •

Copy link
Copy Markdown
Contributor Author

@miketheman can this get merged, or are there any concerns?

Instead of this:

def __new__(cls, *args, **kwargs):

We could perhaps do:

def __new__(cls, family=AF_INET, type=SOCK_STREAM, proto=0, fileno=None)

@miketheman

Copy link
Copy Markdown
Owner

Hi @emontnemery !

I'm lacking context as to why this is an improvement on the existing behavior, as well as any tests to validate the change works as intended.

@miketheman miketheman added enhancement New feature or request more-info-needed Further information is requested labels Oct 6, 2021
@emontnemery

Copy link
Copy Markdown
Contributor Author

The current code throws if the socket is created with its parameters passed as keywords instead of as positional arguments, this PR fixes that by handling both cases.

I've added testcases where socket.socket() is called with keyword arguments or no arguments.

Comment thread pytest_socket.py Outdated
@@ -86,7 +86,10 @@ class GuardedSocket(socket.socket):
""" socket guard to disable socket creation (from pytest-socket) """
def __new__(cls, *args, **kwargs):

@emontnemery emontnemery Oct 7, 2021 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Maybe this should be changed to def __new__(cls, family=AF_INET, type=SOCK_STREAM, proto=0, fileno=None) instead, then we can simply check family, instead of handling both positional and keyword arguments cases.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

@emontnemery emontnemery Dec 13, 2021 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

OK, updated to mimic the CPython implementation, i.e.:

def __new__(cls, family=-1, type=-1, proto=-1, fileno=None)

Comment thread pytest_socket.py Resolved
@qlty-cloud-legacy

Copy link
Copy Markdown

Code Climate has analyzed commit fc0ba71 and detected 0 issues on this pull request.

View more on Code Climate.

@miketheman miketheman removed the more-info-needed Further information is requested label Dec 20, 2021
@miketheman miketheman added this to the 0.50.0 milestone Dec 20, 2021
@miketheman miketheman self-assigned this Dec 20, 2021
@miketheman
miketheman merged commit 6da69ca into miketheman:main Dec 20, 2021
@miketheman

Copy link
Copy Markdown
Owner

Thanks for working through this!

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

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants