python-typing-koans
                                
                                
                                
                                    python-typing-koans copied to clipboard
                            
                            
                            
                        114-medium-factory-pattern
Hey @kracekumar,
Thanks for taking the time to reply to all my past queries. I'm a little stuck on 114 and was wondering if you could provide a hint or suggestion of sorts. I'm currently using overloaded method signatures for  sock_type in the following format:
@overload
def _sock_type(addr: Tuple[str,int])-> Union[TCPSocket,TCP6Socket]:...
@overload
def _sock_type(addr: Union[str, bytes])-> UnixSocket:...
def _sock_type(addr: Address):
      <implementation details>
However, this solution still uses union and unfortunately it also means that sock_type in the line below is TCP Socket, TCP6Socket or Unix Socket whic produces the type error sock_type is not callable.
sock = sock_type(address, conf, log)
Was wondering if you have any hints/suggestions/tips.
Let me know
Glad to see your question and trying out the exercise.
You don't need to use overload for this exercise or refactor the code. While dealing with the inherited classes, most of the time, the child classes will follow the base class signature.  So try using the base class as a type rather than using Union type and see if it works.
Looking forward to your experience.
@J0 did you get it working with the hints from the previous comment?
@kracekumar thanks for checking in! I haven't had time to look at it but will give it a try again tonight and let you know how it goes :)
Done! Think this post: https://stackoverflow.com/questions/55441612/does-mypy-have-a-subclass-acceptable-return-type was particularly helpful
Thanks for the advice :)