Skip to content

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

Merged

Conversation

ava-silver
Copy link
Contributor

@ava-silver ava-silver commented Feb 27, 2025

What does this PR do?

Fixes the typing on __new__ and makes constructors typing behave properly.
before:
image
after:
image

Additional Notes

Review checklist

Please check relevant items below:

  • This PR includes all newly recorded cassettes for any modified tests.

  • This PR does not rely on API client schema changes.

    • The CI should be fully passing.
  • Or, this PR relies on API schema changes and this is a Draft PR to include tests for that new functionality.

    • Note: CI shouldn't be run on this Draft PR, as its expected to fail without the corresponding schema changes.

@ava-silver ava-silver changed the title [TYPING] fix __new__ typing for OpenApiModel fix __new__ typing for OpenApiModel Feb 27, 2025
Copy link
Contributor Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@ava-silver ava-silver marked this pull request as ready for review February 27, 2025 18:14
@ava-silver ava-silver requested review from a team as code owners February 27, 2025 18:14
@ava-silver ava-silver changed the title fix __new__ typing for OpenApiModel fix __new__ typing for OpenApiModel Feb 27, 2025
@@ -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:
...
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a difference between this as pass?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nope! ... (or the singleton Ellipsis) in python is just a convention used to indicate that it is not the real implementation, whereas pass is usually used when the implementation is intentionally blank (like with try: ... except: pass)

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The docs for overload also use ... in their example usage.

@ava-silver
Copy link
Contributor Author

/merge

@dd-devflow
Copy link

dd-devflow bot commented Feb 27, 2025

View all feedbacks in Devflow UI.
2025-02-27 20:15:08 UTC ℹ️ Start processing command /merge


2025-02-27 20:15:16 UTC ℹ️ MergeQueue: waiting for PR to be ready

This merge request is not mergeable yet, because of pending checks/missing approvals. It will be added to the queue as soon as checks pass and/or get approvals.
Note: if you pushed new commits since the last approval, you may need additional approval.
You can remove it from the waiting list with /remove command.


2025-02-27 20:24:14 UTC ⚠️ MergeQueue: This merge request was unqueued

[email protected] unqueued this merge request

@ava-silver
Copy link
Contributor Author

/merge -c

@dd-devflow
Copy link

dd-devflow bot commented Feb 27, 2025

View all feedbacks in Devflow UI.
2025-02-27 20:24:10 UTC ℹ️ Start processing command /merge -c

@ava-silver
Copy link
Contributor Author

/merge

@dd-devflow
Copy link

dd-devflow bot commented Feb 27, 2025

View all feedbacks in Devflow UI.
2025-02-27 20:26:30 UTC ℹ️ Start processing command /merge


2025-02-27 20:26:34 UTC ℹ️ MergeQueue: waiting for PR to be ready

This merge request is not mergeable yet, because of pending checks/missing approvals. It will be added to the queue as soon as checks pass and/or get approvals.
Note: if you pushed new commits since the last approval, you may need additional approval.
You can remove it from the waiting list with /remove command.


2025-02-28 00:27:04 UTC ⚠️ MergeQueue: This merge request was unqueued

devflow unqueued this merge request: It did not become mergeable within the expected time

@ava-silver ava-silver force-pushed the ava.silver/typing/fix-__new__-typing-for-openapimodel branch from 9a34c24 to 4745276 Compare February 28, 2025 20:28
@@ -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
Copy link
Contributor Author

@ava-silver ava-silver Feb 28, 2025

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

@ava-silver ava-silver merged commit 35628c1 into master Feb 28, 2025
13 checks passed
@ava-silver ava-silver deleted the ava.silver/typing/fix-__new__-typing-for-openapimodel branch February 28, 2025 20:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants