Remove Python 2 references from the track (#3437)

* Remove Python 2 references from the track

* Revert unintentional whitespace changes to test files

[no important files changed]
This commit is contained in:
Isaac Good
2023-07-14 05:53:39 -07:00
committed by GitHub
parent 5bb59595d9
commit 29a64a4889
11 changed files with 9 additions and 22 deletions

View File

@@ -82,7 +82,7 @@ False
Strings (`str`) are compared [_lexicographically_][lexographic order], using their individual Unicode code points (_the result of passing each code point in the `str` to the built-in function [`ord()`][ord], which returns an `int`_). Strings (`str`) are compared [_lexicographically_][lexographic order], using their individual Unicode code points (_the result of passing each code point in the `str` to the built-in function [`ord()`][ord], which returns an `int`_).
If all code points in both strings match and are _**in the same order**_, the two strings are considered equal. If all code points in both strings match and are _**in the same order**_, the two strings are considered equal.
This comparison is done in a 'pair-wise' fashion - first-to-first, second-to-second, etc. This comparison is done in a 'pair-wise' fashion - first-to-first, second-to-second, etc.
Unlike in Python 2.x, in Python 3.x, `str` and `bytes` cannot be directly coerced/compared. In Python 3.x, `str` and `bytes` cannot be directly coerced/compared.
```python ```python
>>> 'Python' > 'Rust' >>> 'Python' > 'Rust'

View File

@@ -149,7 +149,7 @@ Use of the `%` operator for formatting is the oldest method of string formatting
It comes from the C language and allows the use of positional arguments to build a `str`. It comes from the C language and allows the use of positional arguments to build a `str`.
This method has been superseded by both `f-strings` and `str.format()`, which is why the nickname for `%` formatting is _'Old Style'_. This method has been superseded by both `f-strings` and `str.format()`, which is why the nickname for `%` formatting is _'Old Style'_.
It can be still found in python 2 and/or legacy code. It can be still found in Python 2 and/or legacy code.
While using this method will work in Python 3.x, `%` formatting is usually avoided because it can be error-prone, is less efficient, has fewer options available, and any placeholder-argument mismatch can raise an exception. While using this method will work in Python 3.x, `%` formatting is usually avoided because it can be error-prone, is less efficient, has fewer options available, and any placeholder-argument mismatch can raise an exception.
Using the `%` operator is similar to [`printf()`][printf-style-docs], so it is also sometimes called _printf formatting_. Using the `%` operator is similar to [`printf()`][printf-style-docs], so it is also sometimes called _printf formatting_.

View File

@@ -22,7 +22,7 @@ The [zen of Python (PEP 20)][the zen of python] and [What is Pythonic?][what is
Tests and tooling for this track currently support `3.7` - `3.10.6` (_tests_) and [`Python 3.11`][311-new-features] (_tooling_). Tests and tooling for this track currently support `3.7` - `3.10.6` (_tests_) and [`Python 3.11`][311-new-features] (_tooling_).
It is highly recommended that students upgrade to at least `Python 3.8`, as some features used by this track may not be supported in earlier versions. It is highly recommended that students upgrade to at least `Python 3.8`, as some features used by this track may not be supported in earlier versions.
That being said, most of the exercises will work with `Python 3.6+`, and many are compatible with `Python 2.7+`. That being said, most of the exercises will work with `Python 3.6+`.
But we don't guarantee support for versions not listed under [Active Python Releases][active-python-releases]. But we don't guarantee support for versions not listed under [Active Python Releases][active-python-releases].
We will try to note when a feature is only available in a certain version. We will try to note when a feature is only available in a certain version.

View File

@@ -6,7 +6,7 @@ Real Python also offers a [nice guide][helpful guide] to installation on various
Finally, these posts by Brett Cannon [A quick-and-dirty guide][quick-and-dirty] and [Why you should use `python -m pip`][python-m-pip], give very helpful advice on how to manage Python installations and packages. Finally, these posts by Brett Cannon [A quick-and-dirty guide][quick-and-dirty] and [Why you should use `python -m pip`][python-m-pip], give very helpful advice on how to manage Python installations and packages.
**Note for MacOS users:** prior to MacOS Monterey (12.3), `Python 2.7` came pre-installed with the operating system. **Note for MacOS users:** prior to MacOS Monterey (12.3), `Python 2.7` came pre-installed with the operating system.
Using `Python 2.7` with Exercism or most other programs is not recommended. Using `Python 2.7` with Exercism or most other programs is not supported.
You should instead install [Python 3][Python-three downloads] via one of the methods detailed below. You should instead install [Python 3][Python-three downloads] via one of the methods detailed below.
As of MacOS Monterey (12.3), no version of Python will be pre-installed via MacOS. As of MacOS Monterey (12.3), no version of Python will be pre-installed via MacOS.
@@ -20,7 +20,7 @@ Some quick links into the documentation by operating system:
Exercism tests and tooling currently support `3.7` - `3.10.6` (_tests_) and [`Python 3.11`][311-new-features] (_tooling_). Exercism tests and tooling currently support `3.7` - `3.10.6` (_tests_) and [`Python 3.11`][311-new-features] (_tooling_).
Exceptions to this support are noted where they occur. Exceptions to this support are noted where they occur.
Most of the exercises will work with `Python 3.6+`, and many are compatible with `Python 2.7+`. Most of the exercises will work with `Python 3.6+`.
But we don't guarantee support for versions not listed under [Active Python Releases][active-python-releases]. But we don't guarantee support for versions not listed under [Active Python Releases][active-python-releases].

View File

@@ -80,7 +80,7 @@ False
Unlike numbers, strings (`str`) are compared [_lexicographically_][lexographic order], using their individual Unicode code points (_the result of passing each code point in the `str` to the built-in function [`ord()`][ord], which returns an `int`_). Unlike numbers, strings (`str`) are compared [_lexicographically_][lexographic order], using their individual Unicode code points (_the result of passing each code point in the `str` to the built-in function [`ord()`][ord], which returns an `int`_).
If all code points in both strings match and are _**in the same order**_, the two strings are considered equal. If all code points in both strings match and are _**in the same order**_, the two strings are considered equal.
This comparison is done in a 'pair-wise' fashion - first-to-first, second-to-second, etc. This comparison is done in a 'pair-wise' fashion - first-to-first, second-to-second, etc.
Unlike in Python 2.x, in Python 3.x, `str` and `bytes` cannot be directly coerced/compared. In Python 3.x, `str` and `bytes` cannot be directly coerced/compared.
```python ```python
>>> 'Python' > 'Rust' >>> 'Python' > 'Rust'

View File

@@ -25,7 +25,7 @@ class CircularBuffer:
self.read_point = 0 self.read_point = 0
self.write_point = 0 self.write_point = 0
# (protected) helper method to support python 2/3 # (protected) helper method
def _update_buffer(self, data): def _update_buffer(self, data):
try: try:
self.buffer[self.write_point] = data self.buffer[self.write_point] = data

View File

@@ -2,9 +2,6 @@
{{ macros.header() }} {{ macros.header() }}
# Python 2/3 compatibility
if not hasattr(unittest.TestCase, 'assertCountEqual'):
unittest.TestCase.assertCountEqual = unittest.TestCase.assertItemsEqual
class {{ exercise | camel_case }}Test(unittest.TestCase): class {{ exercise | camel_case }}Test(unittest.TestCase):
{% for case in cases -%} {% for case in cases -%}

View File

@@ -6,10 +6,6 @@ from pythagorean_triplet import (
# Tests adapted from `problem-specifications//canonical-data.json` # Tests adapted from `problem-specifications//canonical-data.json`
# Python 2/3 compatibility
if not hasattr(unittest.TestCase, "assertCountEqual"):
unittest.TestCase.assertCountEqual = unittest.TestCase.assertItemsEqual
class PythagoreanTripletTest(unittest.TestCase): class PythagoreanTripletTest(unittest.TestCase):
def test_triplets_whose_sum_is_12(self): def test_triplets_whose_sum_is_12(self):

View File

@@ -1,8 +1,7 @@
""" """
This exercise stub and the test suite contain several enumerated constants. This exercise stub and the test suite contain several enumerated constants.
Since Python 2 does not have the enum module, the idiomatic way to write Enumerated constants can be done with a NAME assigned to an arbitrary,
enumerated constants has traditionally been a NAME assigned to an arbitrary,
but unique value. An integer is traditionally used because its memory but unique value. An integer is traditionally used because its memory
efficient. efficient.
It is a common practice to export both constants and functions that work with It is a common practice to export both constants and functions that work with

View File

@@ -341,11 +341,6 @@ known-standard-library=
# Force import order to recognize a module as part of a third party library. # Force import order to recognize a module as part of a third party library.
known-third-party=enchant, absl known-third-party=enchant, absl
# Analyse import fallback blocks. This can be used to support both Python 2 and
# 3 compatible code, which means that the block might have code that exists
# only in one or another interpreter, leading to false positives when analysed.
analyse-fallback-blocks=no
[CLASSES] [CLASSES]

View File

@@ -2,7 +2,7 @@
## Example implementation ## Example implementation
Modified from the existing [example.py](https://github.com/exercism/python/blob/master/exercises/rna-transcription/example.py) to remove Python 2 compatiblity noise: Taken from the existing [example.py](https://github.com/exercism/python/blob/main/exercises/practice/rna-transcription/.meta/example.py):
```python ```python
DNA_TO_RNA = str.maketrans("AGCT", "UCGA") DNA_TO_RNA = str.maketrans("AGCT", "UCGA")