Skip to content

Move types into source, drop Python 3.4#96

Merged
kjd merged 2 commits intokjd:masterfrom
sethmlarson:type-hints-in-source
Jan 29, 2021
Merged

Move types into source, drop Python 3.4#96
kjd merged 2 commits intokjd:masterfrom
sethmlarson:type-hints-in-source

Conversation

@sethmlarson
Copy link
Copy Markdown
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.

label = label.encode('ascii')
ulabel(label)
if not valid_label_length(label):
label_bytes = label.encode('ascii')
Copy link
Copy Markdown
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
Copy Markdown
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

valid_ending = False
number_type = False
number_type = False # type: Union[str, bool]
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks!

result_str = '.'.join(result) + trailing_dot # type: ignore
size += len(trailing_dot)
return (result, size)
return result_str, size
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

3 participants