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

Use string form for type checking until Python 3.7 dropped #1941

Closed
matthewfeickert opened this issue Aug 12, 2022 · 0 comments · Fixed by #1942
Closed

Use string form for type checking until Python 3.7 dropped #1941

matthewfeickert opened this issue Aug 12, 2022 · 0 comments · Fixed by #1942
Assignees
Labels
type checking Related to types and type checking

Comments

@matthewfeickert
Copy link
Member

What the if here? The string form is fine until you drop Pythons that don’t support it.

Originally posted by @henryiii in #1909 (comment)

This was in reference to

if T.TYPE_CHECKING:
    PathOrStr = T.Union[str, os.PathLike[str]]
else:
    PathOrStr = T.Union[str, "os.PathLike[str]"]

in PR #190 now in

pyhf/src/pyhf/typing.py

Lines 30 to 33 in ad1dd86

if TYPE_CHECKING:
PathOrStr = Union[str, os.PathLike[str]]
else:
PathOrStr = Union[str, "os.PathLike[str]"]

So until Python 3.7 is dropped (I think this is the version I am not very up to date with my type checking knowledge) we could instead just drop the if TYPE_CHECKING and use

#TODO: Switch to os.PathLike[str] once Python 3.7 dropped
PathOrStr = Union[str, "os.PathLike[str]"]

This would also allow for reverting PR #1937.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type checking Related to types and type checking
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants