Skip to content

#12243 wsgi: drop Python 2 variants of _wsgiString and _wsgiStringToBytes#12244

Merged
itamarst merged 3 commits intotwisted:trunkfrom
gudnimg:wsgi-remove-python2-code
Jul 20, 2024
Merged

#12243 wsgi: drop Python 2 variants of _wsgiString and _wsgiStringToBytes#12244
itamarst merged 3 commits intotwisted:trunkfrom
gudnimg:wsgi-remove-python2-code

Conversation

@gudnimg
Copy link
Contributor

@gudnimg gudnimg commented Jul 20, 2024

Scope and purpose

Fixes #12243

str is bytes is always False today because Python 2 is no longer supported. This pull request cleans up a few instances where this type check is performed in twisted.web.wsgi.

  • Remove variants of _wsgiString() and _wsgiStringToBytes() methods which were only used for Python 2. Python 3 variants of these functions are not changed.
  • Remove the str is bytes check in _ErrorStream's write() method as it is redundant in Python 3.
  • Added type annotation to _wsgiString(), _wsgiStringToBytes(), _ErrorStream.write() and _ErrorStream.writelines()

The purpose is to simply help with cleanup :)

@codspeed-hq
Copy link

codspeed-hq bot commented Jul 20, 2024

CodSpeed Performance Report

Merging #12244 will not alter performance

Comparing gudnimg:wsgi-remove-python2-code (326ba02) with trunk (f060065)

Summary

✅ 16 untouched benchmarks

@gudnimg
Copy link
Contributor Author

gudnimg commented Jul 20, 2024

please review

I don't see how these changes can explain the benchmark results. There should be no functional change.

@chevah-robot chevah-robot requested a review from a team July 20, 2024 15:56
@gudnimg gudnimg changed the title wsgi: drop Python 2 variants of _wsgiString and _wsgiStringToBytes #12243 wsgi: drop Python 2 variants of _wsgiString and _wsgiStringToBytes Jul 20, 2024
@itamarst
Copy link
Contributor

The benchmarks have some noise, if you rerun probably it'll go away.

'str is bytes' is always False now because Python 2 is no longer supported. Let's drop the Python 2 code and only keep the Python 3 variants of the functions _wsgiString and _wsgiStringToBytes

Also added type annotation to the changed code
@gudnimg gudnimg force-pushed the wsgi-remove-python2-code branch from f94482e to 584cb27 Compare July 20, 2024 21:12
@gudnimg
Copy link
Contributor Author

gudnimg commented Jul 20, 2024

Spotted some more Python 2 code on the 2nd pass 😅

gudnimg added 2 commits July 20, 2024 21:52
I spotted another instance in the code where Twisted is checking if str equals bytes. This is only true on Python 2.

Drop the unnesaccery 'if str is bytes:' statement to simplify the code.

Additionally I added type annotation to the modifed functions.
Today it's always Python 3.
@gudnimg gudnimg force-pushed the wsgi-remove-python2-code branch from c57b253 to 326ba02 Compare July 20, 2024 21:53
@gudnimg
Copy link
Contributor Author

gudnimg commented Jul 20, 2024

Benchmark tests now pass and I've cleaned up the fixup commits with a rebase.

The changes are a bit more than I initially intended, please let me know if you want me to write the newsfragment. I'm not sure if this crosses the line of being 'misc'.

@gudnimg
Copy link
Contributor Author

gudnimg commented Jul 20, 2024

please review

@itamarst
Copy link
Contributor

Thank you!

@itamarst itamarst merged commit 6abe7b3 into twisted:trunk Jul 20, 2024
@gudnimg gudnimg deleted the wsgi-remove-python2-code branch July 20, 2024 22:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Drop Python 2 variants of the functions _wsgiString and _wsgiStringToBytes

3 participants