Repository navigation
Description
RF 5 supports only Python 3 (#3457) so it doesn't itself anymore need code related to Python 2 support. There are, however, various tools and libraries that use Robot's Python 2/3 compatibility layer and removing it altogether would break all of them. These tools/libs being Python 3 compatible themselves doesn't change that: if they use Robot's API that we remove, they will break.
We could just say that all tools/libs that are compatible with RF 5 should be Python-3-only and shouldn't use the old compatibility layer. Most likely most of them would be updated soon, but there likely are various projects that aren't actively maintained and updating could take time and in the worst case require finding a new maintainer. Breaking lot of projects isn't great, and in this case we can easily avoid that by preserving at least the most important parts of the compatibility layer. I strongly believe that's a good idea, especially because doing that is pretty easy.
Although I think we should preserve the compatibility layer, I don't believe we should preserve it fully. The reason is that there are some utils that exists only to workaround bugs in old Jython and IronPython versions that nobody should be using anymore anyway. Some other utils are so specialized that I don't believe they are used at all. I believe we should preserve the most important parts and then add more utils back during the RF 5 preview release time or even after RF 5.0 release if needed.
This is what I think we should preserve:
PY2,PY3,JYTHON,IRONPYTHONandJAVA_VERSIONconstantspy2to3andpy3to2class decoratorsis_unicodefunction (could be an alias foris_string)unicodetype (could be an alias forstr)unicfor safely converting values to Unicode (we still need this utility but it has been renamed tosafe_str)roundupfunction (could be an alias forroundeven though their semantics aren't exactly the same)
The following utils are likely not used a lot or at all. They can be preserved if needed:
with_metaclassfor applying a metaclassStringIO(io.StringIOworks in most cases also with Python 2)MappingandMutableMapping(available incollectionsuntil Python 3.10)unwrapfor unwrapping decorators (available ininspectin Python 3)is_java_initandis_java_methodfor detecting Java based methods
I believe it's enough to document that the preserved utils are deprecated in RF 5. We can then later decide should we somehow more visible deprecate them. That would be pretty easy with functions but constants are a bit trickier. Most likely there's no actual maintenance or performance burden from preserving these utils so there's no urgent need to remove them either.
Activity
pekkaklarck commentedon Nov 24, 2021
If we want to loudly deprecate this API, it's pretty easy with functions. Just need to do something like this:
Constants are harder but this ought to work in most cases:
hugovk commentedon Nov 25, 2021
Constants are easier for Python 3.7+, can use
__getattr__:https://github.com/python-pillow/Pillow/pull/4494/files
pekkaklarck commentedon Nov 27, 2021
Thanks for the tip, using module level
__getattr__is a good idea. Python 3.6 is about to reach EOL so Python 3.7+ solution ought to be fine when it's time to more loudly deprecate these.pekkaklarck commentedon Dec 7, 2021
SeleniumLibrary uses
robot.utils.StringIO(robotframework/SeleniumLibrary#1752). I'm sure they'll remove the usage, but we'd still better add it back to avoid breaking old SL versions.Old Py2/2 compatibility: Add robot.utils.StringIO back
Extend deprecated Python 2/3 compatibility layer (#4150)
pekkaklarck commentedon Feb 16, 2022
robot.utils.platform.PY2was added back to avoid breaking SSHLibrary. See the issue linked above for details.pekkaklarck commentedon Mar 10, 2022
Decided to change all our code to use the standard
roundinstead our Python 2 compatibleroundup. Need to preserveroundupstill. It's implementation will be justroundup = roundwhich means it won't work exactly the same as earlier. If that's a problem, the old implementation can be preserved.Add back, but deprecate, Python 2/3 compatibility layer