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

Incorrect check for NoneType #95

Closed
wants to merge 19 commits into from
Closed

Incorrect check for NoneType #95

wants to merge 19 commits into from

Conversation

jdidion
Copy link
Contributor

@jdidion jdidion commented Feb 21, 2024

Fixes the check for NoneType. type(type(None)) returns <class type>, and so isinstance(type_, type(type(None))) always returns True. Instead, we want type_ is type(None).

I found that one file fgpyo.fasta.builder is formatted differently with black 20.8b1 (which I had installed locally) vs 23.3.0 (the latest version, which is installed during CI), causing a build failure, so I just updated the minimum to the latest version.

I added support for 3.11. We cannot add support for 3.12 without dropping support for 3.7 due to the python versions supported by different versions of Poetry. Thus, I explicitly limited the supported versions for fgpyo in pyproject.toml to 3.7-3.11.

I updated the formatting of pyproject.toml based on my IDE's built-in TOML formatter.

I have removed 3.7 from the CI test matrix because it is failing with some gnarly mypy errors that are not there in more recent versions (in which support for 3.7 has been dropped). I advocate dropping support for 3.7 as it is EOL. That would allow us to get rid of dependencies and code in inspect.py and types.py that are only there to maintain 3.7 compatibility.

Closes #94

@jdidion jdidion requested review from nh13 and clintval February 21, 2024 22:53
Copy link

codecov bot commented Feb 21, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (94b3696) 93.34% compared to head (356ef34) 93.04%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #95      +/-   ##
==========================================
- Coverage   93.34%   93.04%   -0.30%     
==========================================
  Files          32       32              
  Lines        3364     3364              
  Branches      619      695      +76     
==========================================
- Hits         3140     3130      -10     
- Misses        149      159      +10     
  Partials       75       75              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jdidion
Copy link
Contributor Author

jdidion commented Feb 21, 2024

I think the codecov failure is due to extra lines being added by black reformatting. Would appreciate if we can merge despite that failure.

@jdidion jdidion changed the title Nested call to type is not necessary Incorrect check for NoneType Feb 22, 2024
@jdidion jdidion requested review from msto and TedBrookings February 22, 2024 00:00
Copy link
Member

@nh13 nh13 left a comment

Choose a reason for hiding this comment

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

Thank-you for fixing all this. Nonetheless, there's a lot of other fixes that are not related to this PR, though nice to have in general (again thank-you!). I'd much prefer to see separate PRs for each (e.g. dropping 3.7 support, adding 3.11 support, reformatting TOML, fix black formatting, etc). If that's too onerous, I would want to see individual commits for the above, to make it clear the intent of each set of changes. Is it too onerous to do either at this point?

@@ -226,7 +228,7 @@ def dict_parse(dict_string: str) -> Dict[Any, Any]:
return types.make_enum_parser(type_)
elif types.is_constructible_from_str(type_):
return functools.partial(type_)
elif isinstance(type_, type(type(None))):
elif type_ is type(None): # noqa: E721
Copy link
Member

Choose a reason for hiding this comment

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

can you please add a test?

Copy link
Contributor

Choose a reason for hiding this comment

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

@jdidion following up on your question from Slack, I think this is the right approach.

as far as I'm aware, flake8 guards against type(x) == int and the like. We're doing equality checks against types above (e.g. if type_ == bool) and flake8 doesn't complain, I'm guessing because we don't call type() in the same line.

If you wanted to avoid the noqa, you could declare NoneType = type(None) above (or in fgpyo.types and import it), then replace this line with elif type_ is NoneType. But this feels like an edge case in flake8, so I think what you have is fine if you're fine with it

@jdidion jdidion marked this pull request as draft February 22, 2024 16:46
@jdidion jdidion removed request for msto and clintval February 22, 2024 16:46
@jdidion jdidion removed the request for review from TedBrookings February 22, 2024 16:46
@jdidion jdidion closed this Feb 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

from_attr returns a none_parser rather than throw ParserNotFound
3 participants