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

Move types into source, drop Python 3.4 #96

Merged
merged 2 commits into from Jan 29, 2021

Conversation

sethmlarson
Copy link
Collaborator

Follow-up from #94 where dropping Python 3.4 support was accepted:

  • Moved all type hints into the source code
  • Removed Python 3.4 from CI
  • Updated python_requires to >=3.5
  • Added type hints into generated code where needed

Also while working on this I discovered that idna.codec is not tested and looks broken. The test suite in test_codec tests the standard library idna codec and not the one provided by this library. I can work on fixing that issue in a separate PR.

idna/codec.py Outdated Show resolved Hide resolved
label = label.encode('ascii')
ulabel(label)
if not valid_label_length(label):
label_bytes = label.encode('ascii')
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Had to make this label_bytes change because mypy doesn't like setting bytes to a variable previously typed as str. Used label_bytes throughout in this file.

@sethmlarson
Copy link
Collaborator Author

Will move all the types into comments to adhere to Python 3.5 compatible type hinting.

@sethmlarson sethmlarson force-pushed the type-hints-in-source branch 2 times, most recently from 63c9e0c to a49e484 Compare January 23, 2021 22:12
idna/core.py Outdated
@@ -84,7 +88,7 @@ def check_bidi(label, check_ltr=False):
raise IDNABidiError('First codepoint in label {} must be directionality L, R or AL'.format(repr(label)))

valid_ending = False
number_type = False
number_type = False # type: Union[str, bool]
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this be simplified into number_type = None # type: str by also updating the condition on L106 to if number_type is None?

(unicodedata.bidirectional may return an empty string value)

If so, perhaps fair to do that in a separate changeset if it'd be misleading or confusing to apply it at the same time as the other changes here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, perhaps number_type = None # type: Optional[str] would be the way to go (making the nullability of the type explicit)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Changed this to Optional[str]

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks!

size += len(trailing_dot)
return (result, size)
return result_str, size
Copy link
Contributor

Choose a reason for hiding this comment

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

Again possibly not the correct moment to modify this within the current pull request, but I wonder if it's possible to simplify the logic around the returned string value and size variable. In particular: is size always equal to len(result_str)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This whole file needs a lot of work, I mentioned it in initial PR message that I'm almost certain the idna.codec module is not functional. Would recommend solving all these problems in a different PR.

@sethmlarson
Copy link
Collaborator Author

sethmlarson commented Jan 28, 2021

@kjd I believe this is ready for review. Squash this on merge, the second commit is only to show that this change isn't required to merge and I can rollback if needed.

@kjd
Copy link
Owner

kjd commented Jan 29, 2021

Thanks!

I agree that the codec implementation hasn't been looked at since the very first version and needs some attention.

@kjd kjd merged commit b0ef4bf into kjd:master Jan 29, 2021
@sethmlarson sethmlarson deleted the type-hints-in-source branch January 29, 2021 15:32
@wbolster wbolster mentioned this pull request May 19, 2021
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.

None yet

3 participants