-
-
Notifications
You must be signed in to change notification settings - Fork 107
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
Improve typehints for singular_noun #186
Improve typehints for singular_noun #186
Conversation
What is the problem you encountered? |
@jaraco Let's say you want to get a singular version of the word but you don't know whether the word is already singular. import inflect
p = inflect.engine()
def get_singular(word: str) -> str:
new_word = p.singular_noun(word)
if new_word is False:
return word
return new_word At this point any adequate type checker will tell you that you can't return new_word because its type is Essentially I am just making the type hints here more specific to make sure that type checkers are not angry and for correctness. |
a099bff
to
0bcc550
Compare
@@ -24,6 +24,7 @@ include_package_data = true | |||
python_requires = >=3.7 | |||
install_requires = | |||
pydantic >= 1.9.1 | |||
typing_extensions >= 3.7.2 |
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.
Why 3.7.2? I looked up the changelog, but it directs to the git history for versions prior to 4.0. I don't want to add a specific version unless there was a specific reason for the minimum pertinent to this project.
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.
I believe that Literal wasn't added until this version. Any version can be picked as long as it's after this one.
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.
Okay. I did confirm the introduction of Literal
appears in the changelog between 3.6.6 and 3.7.4. There's no tag for 3.7.2, unfortunately, leaving it difficult to confirm that the feature was added in that version. Since we're not certain and because those releases are already years old and because this project is likely to depend on features later than that release, I'll just leave it unspecified (when I merge).
Please note that I am only fixing the problem that I personally encountered. If this pattern of "value or False" is more common in the library -- we'd need to fix those cases as well :)