-
Notifications
You must be signed in to change notification settings - Fork 48
fix __new__
typing for OpenApiModel
#2433
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,8 +11,8 @@ import pprint | |
import re | ||
import tempfile | ||
from types import MappingProxyType | ||
from typing import Collection, Mapping, Union | ||
from typing_extensions import Final | ||
from typing import Collection, Mapping, Union, overload | ||
from typing_extensions import Final, Self | ||
|
||
from dateutil.parser import parse | ||
|
||
|
@@ -89,7 +89,7 @@ def composed_model_input_classes(cls): | |
return [] | ||
|
||
|
||
class OpenApiModel(object): | ||
class OpenApiModel: | ||
"""The base class for all OpenAPIModels. | ||
|
||
:var attribute_map: The key is attribute name and the value is json | ||
|
@@ -173,6 +173,18 @@ class OpenApiModel(object): | |
"""Get the value of an attribute using dot notation: `instance.attr`.""" | ||
return self.__getitem__(attr) | ||
|
||
@overload | ||
def __new__(cls, arg: None) -> None: # type: ignore | ||
... | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a difference between this as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nope! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. tldr they both do nothing, but conventionally you would use ellipses for overload signature bodies There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The docs for overload also use |
||
|
||
@overload | ||
def __new__(cls, arg: "ModelComposed") -> Self: | ||
... | ||
|
||
@overload | ||
def __new__(cls, *args, **kwargs) -> Self: | ||
... | ||
|
||
def __new__(cls, *args, **kwargs): | ||
if len(args) == 1: | ||
arg = args[0] | ||
|
@@ -185,7 +197,7 @@ class OpenApiModel(object): | |
oneof_instance = get_oneof_instance(cls, model_kwargs, kwargs, model_arg=arg) | ||
return oneof_instance | ||
|
||
return super(OpenApiModel, cls).__new__(cls) | ||
return super().__new__(cls) | ||
|
||
def __init__(self, kwargs): | ||
""" | ||
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
had to add the type ignore because mypy (in CI) doesn't like this, but we do this in the code already, we just didn't reflect that in the typing before