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

Add optional type hinting to arguments #4455

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

DominicOram
Copy link

@DominicOram DominicOram commented Feb 28, 2025

Description

Adds Optional type hint in all places where arguments default to None and so are clearly Optional

Note the first commit is the changes that I would like for my application. 2nd one is just me trying to fix the same issue elsewhere. If there is something controversial about the second commit I'm happy to drop it.

Fixes #4454

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

  1. Temporarily comment out typeCheckingMode = "off" in the pyproject.toml
  2. Run pyright . on main and see 1560 errors
  3. Run pyright . on this branch and see 1508 errors

Does This PR Require a Contrib Repo Change?

Don't think so?

  • Yes. - Link to PR:
  • No.

Checklist:

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

@DominicOram DominicOram requested a review from a team as a code owner February 28, 2025 12:10
Copy link

linux-foundation-easycla bot commented Feb 28, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

Copy link
Contributor

@xrmx xrmx left a comment

Choose a reason for hiding this comment

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

If you add from __future__ import annotations you can avoid importing Optional and use | None syntax, while you are at it you may also drop the usage of Dict and List and use dict and list instead.

@DominicOram
Copy link
Author

If you add from __future__ import annotations you can avoid importing Optional and use | None syntax, while you are at it you may also drop the usage of Dict and List and use dict and list instead.

My reasoning was that the Optional style is what's currently used in most places and I wanted to keep consistency but happy to change to this.

@DominicOram
Copy link
Author

If you add from __future__ import annotations you can avoid importing Optional and use | None syntax, while you are at it you may also drop the usage of Dict and List and use dict and list instead.

Updated the places where I have changed something and a few places in the same area to keep some consistency. I would be happy to do more but feels like a new PR as it would be a big change and I would rather get my original issue fixed sooner

@xrmx xrmx enabled auto-merge (squash) March 3, 2025 10:14
@xrmx xrmx added the Skip Changelog PRs that do not require a CHANGELOG.md entry label Mar 3, 2025
@xrmx
Copy link
Contributor

xrmx commented Mar 3, 2025

I've filed this open-telemetry/opentelemetry-python-contrib#3320 because this PR failed at least three times that test. Since this continues to fail maybe it's not a flaky test and we are introducing a regression somewhere here instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Skip Changelog PRs that do not require a CHANGELOG.md entry
Projects
None yet
Development

Successfully merging this pull request may close these issues.

No optional type hinting on some optional constructor args
4 participants