Typing vs Python2.7 support
MihanixA opened this issue · 5 comments
Problem description
Typing doesn't work with petl
like an example below.
import petl
def transform(src: Tuple) -> Tuple[tuple, ...]:
table = petl.wrap(src)
res: petl.Table = table.addfield('new_field', lambda _: 'new value')
return res.tupleoftuples()
In our project we use typing a lot and we believe it helps to deliver better code.
Versions
Typing is not compatible with Python 2 and is not fully compatible with some older versions. Adding typing would break support for Python 2.7 (which is deprecated tho).
POC: #559
Questions to discuss
Is there any plans to deprecate Python2.7 and add support for new features e.g. typing, or moving to new repo petl3
or so?
Hi @MihanixA,
Yes, there is some talk for moving petl
forward.
@alimanfoo exposed his thoughts on petl 2.0 roadmap and maintenance.
Basically, the plan is:
- Drop support for Python 2.7
- Migrate from
nosetests
topytest
- Break compatibility with some quirks
Additionally:
- Typing can be a good feature/motivation to drive
petl
to a major version change like2.0
- Nowadays, the majority of work is done by volunteers, so there is the need for somebody to commit to such endeavor.
- Of course, doing the required changes in incremental steps and keeping the compatibility at maximum is well desired
- Patches and PRs welcome!
There is a workaround that could help for adding type hints to petl
.
Function annotations were introduced in PEP 3107 for Python 3.0. The usage of annotations as type hints was formalized in PEP 484 for Python 3.5+.
Any version before 3.0 then will not support the syntax you are using for type hints at all. However, PEP 484 offers a workaround, which some editors may choose to honor. In your case, the hints would look like this:
def get_default_device(use_gpu=True):
# type: (bool) -> cl.Device
...
Or more verbosely:
def get_default_device(use_gpu=True # type: bool
):
# type: (...) -> cl.Device
...
The PEP explicitly states that this form of type hinting should work for any version of Python, if it is supported at all.
Funny that the typing used in the micro PR in OPs post is also outdated. Starting with 3.9, typing.List
is deprecated
https://docs.python.org/3.9/library/typing.html#typing.List
What's the current stance on python2 support? If you want to drop it, what python3 version do you want to support @juarezr ?
Hi @tomwojcik,
- Current
petl
code has many shims for retro-compatibility for many Python versions. - We support as many as it would be practical.
- However, it's possible that we can rethink this if:
- Supporting a specific version becomes a burden
- It doesn't break others' applications
- There is somebody willing to code it.
We support as many as it would be practical.
That's relative. WDYT about supporting only the ones that are supported officially?
https://devguide.python.org/versions/
3.6 is EoL. 3.7 is EoL in a month. I'd say if someone was to add typing and what not, we should support 3.7+. What do you think?